external/efivar
Revision | c3c553db85ff10890209d0fe48fb4856ad68e4e0 (tree) |
---|---|
Time | 2019-02-22 05:27:09 |
Author | Peter Jones <pjones@redh...> |
Commiter | Peter Jones |
Fix all the places -Werror=address-of-packed-member catches.
This gets rid of all the places GCC 9's -Werror=address-of-packed-member
flags as problematic.
Fixes github issue #123
Signed-off-by: Peter Jones <pjones@redhat.com>
@@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) | ||
620 | 620 | ) / sizeof(efi_ip_addr_t); |
621 | 621 | format(buf, size, off, "Dns", "Dns("); |
622 | 622 | for (int i=0; i < end; i++) { |
623 | - const efi_ip_addr_t *addr = &dp->dns.addrs[i]; | |
623 | + efi_ip_addr_t addr; | |
624 | + | |
625 | + memcpy(&addr, &dp->dns.addrs[i], sizeof(addr)); | |
624 | 626 | if (i != 0) |
625 | 627 | format(buf, size, off, "Dns", ","); |
626 | 628 | format_ip_addr(buf, size, off, "Dns", |
627 | - dp->dns.is_ipv6, addr); | |
629 | + dp->dns.is_ipv6, &addr); | |
628 | 630 | } |
629 | 631 | format(buf, size, off, "Dns", ")"); |
630 | 632 | break; |
@@ -71,13 +71,9 @@ | ||
71 | 71 | int _rc; \ |
72 | 72 | char *_guidstr = NULL; \ |
73 | 73 | efi_guid_t _guid; \ |
74 | - const efi_guid_t * const _guid_p = \ | |
75 | - likely(__alignof__(guid) == sizeof(guid)) \ | |
76 | - ? guid \ | |
77 | - : &_guid; \ | |
78 | - \ | |
79 | - if (unlikely(__alignof__(guid) == sizeof(guid))) \ | |
80 | - memmove(&_guid, guid, sizeof(_guid)); \ | |
74 | + const efi_guid_t * const _guid_p = &_guid; \ | |
75 | + \ | |
76 | + memmove(&_guid, guid, sizeof(_guid)); \ | |
81 | 77 | _rc = efi_guid_to_str(_guid_p, &_guidstr); \ |
82 | 78 | if (_rc < 0) { \ |
83 | 79 | efi_error("could not build %s GUID DP string", \ |
@@ -86,7 +82,7 @@ | ||
86 | 82 | _guidstr = onstack(_guidstr, \ |
87 | 83 | strlen(_guidstr)+1); \ |
88 | 84 | _rc = format(buf, size, off, dp_type, "%s", \ |
89 | - _guidstr); \ | |
85 | + _guidstr); \ | |
90 | 86 | } \ |
91 | 87 | _rc; \ |
92 | 88 | }) |
@@ -31,7 +31,7 @@ | ||
31 | 31 | extern const efi_guid_t efi_guid_zero; |
32 | 32 | |
33 | 33 | int NONNULL(1, 2) PUBLIC |
34 | -efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b) | |
34 | +efi_guid_cmp(const void * const a, const void * const b) | |
35 | 35 | { |
36 | 36 | return memcmp(a, b, sizeof (efi_guid_t)); |
37 | 37 | } |
@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid) | ||
128 | 128 | |
129 | 129 | extern int efi_guid_is_zero(const efi_guid_t *guid); |
130 | 130 | extern int efi_guid_is_empty(const efi_guid_t *guid); |
131 | -extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b); | |
131 | +extern int efi_guid_cmp(const void * const a, const void * const b); | |
132 | 132 | |
133 | 133 | /* import / export functions */ |
134 | 134 | typedef struct efi_variable efi_variable_t; |
@@ -23,16 +23,21 @@ | ||
23 | 23 | (((val) & ((mask) << (shift))) >> (shift)) |
24 | 24 | |
25 | 25 | static inline size_t UNUSED |
26 | -ucs2len(const uint16_t * const s, ssize_t limit) | |
26 | +ucs2len(const void *vs, ssize_t limit) | |
27 | 27 | { |
28 | 28 | ssize_t i; |
29 | - for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++) | |
29 | + const uint16_t *s = vs; | |
30 | + const uint8_t *s8 = vs; | |
31 | + | |
32 | + for (i = 0; | |
33 | + i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; | |
34 | + i++, s8 += 2, s++) | |
30 | 35 | ; |
31 | 36 | return i; |
32 | 37 | } |
33 | 38 | |
34 | 39 | static inline size_t UNUSED |
35 | -ucs2size(const uint16_t * const s, ssize_t limit) | |
40 | +ucs2size(const void *s, ssize_t limit) | |
36 | 41 | { |
37 | 42 | size_t rc = ucs2len(s, limit); |
38 | 43 | rc *= sizeof (uint16_t); |
@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit) | ||
69 | 74 | } |
70 | 75 | |
71 | 76 | static inline unsigned char * UNUSED |
72 | -ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) | |
77 | +ucs2_to_utf8(const void * const voidchars, ssize_t limit) | |
73 | 78 | { |
74 | 79 | ssize_t i, j; |
75 | 80 | unsigned char *ret; |
81 | + const uint16_t * const chars = voidchars; | |
76 | 82 | |
77 | 83 | if (limit < 0) |
78 | 84 | limit = ucs2len(chars, -1); |
@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) | ||
124 | 130 | } |
125 | 131 | |
126 | 132 | static inline ssize_t UNUSED NONNULL(4) |
127 | -utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) | |
133 | +utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8) | |
128 | 134 | { |
129 | 135 | ssize_t req; |
130 | 136 | ssize_t i, j; |
137 | + uint16_t *ucs2 = ucs2void; | |
138 | + uint16_t val16; | |
131 | 139 | |
132 | 140 | if (!ucs2 && size > 0) { |
133 | 141 | errno = EINVAL; |
@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) | ||
162 | 170 | val = utf8[i] & 0x7f; |
163 | 171 | i += 1; |
164 | 172 | } |
165 | - ucs2[j] = val; | |
173 | + val16 = val; | |
174 | + ucs2[j] = val16; | |
175 | + } | |
176 | + if (terminate) { | |
177 | + val16 = 0; | |
178 | + ucs2[j++] = val16; | |
166 | 179 | } |
167 | - if (terminate) | |
168 | - ucs2[j++] = (uint16_t)0; | |
169 | 180 | return j; |
170 | 181 | }; |
171 | 182 |