|
| 1 | +From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Peter Jones < [email protected]> |
| 3 | +Date: Thu, 21 Feb 2019 15:20:12 -0500 |
| 4 | +Subject: [PATCH] Fix all the places -Werror=address-of-packed-member catches. |
| 5 | + |
| 6 | +This gets rid of all the places GCC 9's -Werror=address-of-packed-member |
| 7 | +flags as problematic. |
| 8 | + |
| 9 | +Fixes github issue #123 |
| 10 | + |
| 11 | +Signed-off-by: Peter Jones < [email protected]> |
| 12 | +--- |
| 13 | + src/dp-message.c | 6 ++++-- |
| 14 | + src/dp.h | 12 ++++-------- |
| 15 | + src/guid.c | 2 +- |
| 16 | + src/include/efivar/efivar.h | 2 +- |
| 17 | + src/ucs2.h | 27 +++++++++++++++++++-------- |
| 18 | + 5 files changed, 29 insertions(+), 20 deletions(-) |
| 19 | + |
| 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]; |
| 29 | ++ efi_ip_addr_t addr; |
| 30 | ++ |
| 31 | ++ memcpy(&addr, &dp->dns.addrs[i], sizeof(addr)); |
| 32 | + if (i != 0) |
| 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); |
| 37 | + } |
| 38 | + format(buf, size, off, "Dns", ")"); |
| 39 | + break; |
| 40 | +diff --git a/src/dp.h b/src/dp.h |
| 41 | +index 20cb608..1f921d5 100644 |
| 42 | +--- a/src/dp.h |
| 43 | ++++ b/src/dp.h |
| 44 | +@@ -71,13 +71,9 @@ |
| 45 | + int _rc; \ |
| 46 | + char *_guidstr = NULL; \ |
| 47 | + efi_guid_t _guid; \ |
| 48 | +- const efi_guid_t * const _guid_p = \ |
| 49 | +- likely(__alignof__(guid) == sizeof(guid)) \ |
| 50 | +- ? guid \ |
| 51 | +- : &_guid; \ |
| 52 | +- \ |
| 53 | +- if (unlikely(__alignof__(guid) == sizeof(guid))) \ |
| 54 | +- memmove(&_guid, guid, sizeof(_guid)); \ |
| 55 | ++ const efi_guid_t * const _guid_p = &_guid; \ |
| 56 | ++ \ |
| 57 | ++ memmove(&_guid, guid, sizeof(_guid)); \ |
| 58 | + _rc = efi_guid_to_str(_guid_p, &_guidstr); \ |
| 59 | + if (_rc < 0) { \ |
| 60 | + efi_error("could not build %s GUID DP string", \ |
| 61 | +@@ -86,7 +82,7 @@ |
| 62 | + _guidstr = onstack(_guidstr, \ |
| 63 | + strlen(_guidstr)+1); \ |
| 64 | + _rc = format(buf, size, off, dp_type, "%s", \ |
| 65 | +- _guidstr); \ |
| 66 | ++ _guidstr); \ |
| 67 | + } \ |
| 68 | + _rc; \ |
| 69 | + }) |
| 70 | +diff --git a/src/guid.c b/src/guid.c |
| 71 | +index 306c9ff..3156b3b 100644 |
| 72 | +--- a/src/guid.c |
| 73 | ++++ b/src/guid.c |
| 74 | +@@ -31,7 +31,7 @@ |
| 75 | + extern const efi_guid_t efi_guid_zero; |
| 76 | + |
| 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) |
| 80 | + { |
| 81 | + return memcmp(a, b, sizeof (efi_guid_t)); |
| 82 | + } |
| 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) |
| 88 | + |
| 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); |
| 93 | + |
| 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 |
| 98 | +--- a/src/ucs2.h |
| 99 | ++++ b/src/ucs2.h |
| 100 | +@@ -23,16 +23,21 @@ |
| 101 | + (((val) & ((mask) << (shift))) >> (shift)) |
| 102 | + |
| 103 | + static inline size_t UNUSED |
| 104 | +-ucs2len(const uint16_t * const s, ssize_t limit) |
| 105 | ++ucs2len(const void *vs, ssize_t limit) |
| 106 | + { |
| 107 | + ssize_t i; |
| 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; |
| 111 | ++ |
| 112 | ++ for (i = 0; |
| 113 | ++ i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; |
| 114 | ++ i++, s8 += 2, s++) |
| 115 | + ; |
| 116 | + return i; |
| 117 | + } |
| 118 | + |
| 119 | + static inline size_t UNUSED |
| 120 | +-ucs2size(const uint16_t * const s, ssize_t limit) |
| 121 | ++ucs2size(const void *s, ssize_t limit) |
| 122 | + { |
| 123 | + size_t rc = ucs2len(s, limit); |
| 124 | + rc *= sizeof (uint16_t); |
| 125 | +@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit) |
| 126 | + } |
| 127 | + |
| 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) |
| 131 | + { |
| 132 | + ssize_t i, j; |
| 133 | + unsigned char *ret; |
| 134 | ++ const uint16_t * const chars = voidchars; |
| 135 | + |
| 136 | + if (limit < 0) |
| 137 | + limit = ucs2len(chars, -1); |
| 138 | +@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) |
| 139 | + } |
| 140 | + |
| 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) |
| 144 | + { |
| 145 | + ssize_t req; |
| 146 | + ssize_t i, j; |
| 147 | ++ uint16_t *ucs2 = ucs2void; |
| 148 | ++ uint16_t val16; |
| 149 | + |
| 150 | + if (!ucs2 && size > 0) { |
| 151 | + errno = EINVAL; |
| 152 | +@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) |
| 153 | + val = utf8[i] & 0x7f; |
| 154 | + i += 1; |
| 155 | + } |
| 156 | +- ucs2[j] = val; |
| 157 | ++ val16 = val; |
| 158 | ++ ucs2[j] = val16; |
| 159 | ++ } |
| 160 | ++ if (terminate) { |
| 161 | ++ val16 = 0; |
| 162 | ++ ucs2[j++] = val16; |
| 163 | + } |
| 164 | +- if (terminate) |
| 165 | +- ucs2[j++] = (uint16_t)0; |
| 166 | + return j; |
| 167 | + }; |
| 168 | + |
0 commit comments