1 From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001
2 From: Peter Jones <pjones@redhat.com>
3 Date: Thu, 21 Feb 2019 15:20:12 -0500
4 Subject: [PATCH] Fix all the places -Werror=address-of-packed-member catches.
6 This gets rid of all the places GCC 9's -Werror=address-of-packed-member
9 Fixes github issue #123
11 Signed-off-by: Peter Jones <pjones@redhat.com>
13 src/dp-message.c | 6 ++++--
14 src/dp.h | 12 ++++--------
16 src/include/efivar/efivar.h | 2 +-
17 src/ucs2.h | 27 +++++++++++++++++++--------
18 5 files changed, 29 insertions(+), 20 deletions(-)
20 diff --git a/src/dp-message.c b/src/dp-message.c
21 index 3724e5f..9f96466 100644
22 --- a/src/dp-message.c
23 +++ b/src/dp-message.c
24 @@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp)
25 ) / sizeof(efi_ip_addr_t);
26 format(buf, size, off, "Dns", "Dns(");
27 for (int i=0; i < end; i++) {
28 - const efi_ip_addr_t *addr = &dp->dns.addrs[i];
31 + memcpy(&addr, &dp->dns.addrs[i], sizeof(addr));
33 format(buf, size, off, "Dns", ",");
34 format_ip_addr(buf, size, off, "Dns",
35 - dp->dns.is_ipv6, addr);
36 + dp->dns.is_ipv6, &addr);
38 format(buf, size, off, "Dns", ")");
40 diff --git a/src/dp.h b/src/dp.h
41 index 20cb608..1f921d5 100644
46 char *_guidstr = NULL; \
48 - const efi_guid_t * const _guid_p = \
49 - likely(__alignof__(guid) == sizeof(guid)) \
53 - if (unlikely(__alignof__(guid) == sizeof(guid))) \
54 - memmove(&_guid, guid, sizeof(_guid)); \
55 + const efi_guid_t * const _guid_p = &_guid; \
57 + memmove(&_guid, guid, sizeof(_guid)); \
58 _rc = efi_guid_to_str(_guid_p, &_guidstr); \
60 efi_error("could not build %s GUID DP string", \
62 _guidstr = onstack(_guidstr, \
63 strlen(_guidstr)+1); \
64 _rc = format(buf, size, off, dp_type, "%s", \
70 diff --git a/src/guid.c b/src/guid.c
71 index 306c9ff..3156b3b 100644
75 extern const efi_guid_t efi_guid_zero;
77 int NONNULL(1, 2) PUBLIC
78 -efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
79 +efi_guid_cmp(const void * const a, const void * const b)
81 return memcmp(a, b, sizeof (efi_guid_t));
83 diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h
84 index 316891c..ad6449d 100644
85 --- a/src/include/efivar/efivar.h
86 +++ b/src/include/efivar/efivar.h
87 @@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid)
89 extern int efi_guid_is_zero(const efi_guid_t *guid);
90 extern int efi_guid_is_empty(const efi_guid_t *guid);
91 -extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b);
92 +extern int efi_guid_cmp(const void * const a, const void * const b);
94 /* import / export functions */
95 typedef struct efi_variable efi_variable_t;
96 diff --git a/src/ucs2.h b/src/ucs2.h
97 index dbb5900..edd8367 100644
101 (((val) & ((mask) << (shift))) >> (shift))
103 static inline size_t UNUSED
104 -ucs2len(const uint16_t * const s, ssize_t limit)
105 +ucs2len(const void *vs, ssize_t limit)
108 - for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++)
109 + const uint16_t *s = vs;
110 + const uint8_t *s8 = vs;
113 + i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0;
119 static inline size_t UNUSED
120 -ucs2size(const uint16_t * const s, ssize_t limit)
121 +ucs2size(const void *s, ssize_t limit)
123 size_t rc = ucs2len(s, limit);
124 rc *= sizeof (uint16_t);
125 @@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit)
128 static inline unsigned char * UNUSED
129 -ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
130 +ucs2_to_utf8(const void * const voidchars, ssize_t limit)
134 + const uint16_t * const chars = voidchars;
137 limit = ucs2len(chars, -1);
138 @@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit)
141 static inline ssize_t UNUSED NONNULL(4)
142 -utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
143 +utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8)
147 + uint16_t *ucs2 = ucs2void;
150 if (!ucs2 && size > 0) {
152 @@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8)
153 val = utf8[i] & 0x7f;
165 - ucs2[j++] = (uint16_t)0;