1From c3c553db85ff10890209d0fe48fb4856ad68e4e0 Mon Sep 17 00:00:00 2001 2From: Peter Jones <pjones@redhat.com> 3Date: Thu, 21 Feb 2019 15:20:12 -0500 4Subject: [PATCH] Fix all the places -Werror=address-of-packed-member catches. 5 6This gets rid of all the places GCC 9's -Werror=address-of-packed-member 7flags as problematic. 8 9Fixes github issue #123 10 11Signed-off-by: Peter Jones <pjones@redhat.com> 12[james.hilliard1@gmail.com: backport from upstream commit 13c3c553db85ff10890209d0fe48fb4856ad68e4e0] 14Signed-off-by: James Hilliard <james.hilliard1@gmail.com> 15--- 16 src/dp-message.c | 6 ++++-- 17 src/dp.h | 12 ++++-------- 18 src/guid.c | 2 +- 19 src/include/efivar/efivar.h | 2 +- 20 src/ucs2.h | 27 +++++++++++++++++++-------- 21 5 files changed, 29 insertions(+), 20 deletions(-) 22 23diff --git a/src/dp-message.c b/src/dp-message.c 24index 3724e5f..9f96466 100644 25--- a/src/dp-message.c 26+++ b/src/dp-message.c 27@@ -620,11 +620,13 @@ _format_message_dn(char *buf, size_t size, const_efidp dp) 28 ) / sizeof(efi_ip_addr_t); 29 format(buf, size, off, "Dns", "Dns("); 30 for (int i=0; i < end; i++) { 31- const efi_ip_addr_t *addr = &dp->dns.addrs[i]; 32+ efi_ip_addr_t addr; 33+ 34+ memcpy(&addr, &dp->dns.addrs[i], sizeof(addr)); 35 if (i != 0) 36 format(buf, size, off, "Dns", ","); 37 format_ip_addr(buf, size, off, "Dns", 38- dp->dns.is_ipv6, addr); 39+ dp->dns.is_ipv6, &addr); 40 } 41 format(buf, size, off, "Dns", ")"); 42 break; 43diff --git a/src/dp.h b/src/dp.h 44index 20cb608..1f921d5 100644 45--- a/src/dp.h 46+++ b/src/dp.h 47@@ -71,13 +71,9 @@ 48 int _rc; \ 49 char *_guidstr = NULL; \ 50 efi_guid_t _guid; \ 51- const efi_guid_t * const _guid_p = \ 52- likely(__alignof__(guid) == sizeof(guid)) \ 53- ? guid \ 54- : &_guid; \ 55- \ 56- if (unlikely(__alignof__(guid) == sizeof(guid))) \ 57- memmove(&_guid, guid, sizeof(_guid)); \ 58+ const efi_guid_t * const _guid_p = &_guid; \ 59+ \ 60+ memmove(&_guid, guid, sizeof(_guid)); \ 61 _rc = efi_guid_to_str(_guid_p, &_guidstr); \ 62 if (_rc < 0) { \ 63 efi_error("could not build %s GUID DP string", \ 64@@ -86,7 +82,7 @@ 65 _guidstr = onstack(_guidstr, \ 66 strlen(_guidstr)+1); \ 67 _rc = format(buf, size, off, dp_type, "%s", \ 68- _guidstr); \ 69+ _guidstr); \ 70 } \ 71 _rc; \ 72 }) 73diff --git a/src/guid.c b/src/guid.c 74index 306c9ff..3156b3b 100644 75--- a/src/guid.c 76+++ b/src/guid.c 77@@ -31,7 +31,7 @@ 78 extern const efi_guid_t efi_guid_zero; 79 80 int NONNULL(1, 2) PUBLIC 81-efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b) 82+efi_guid_cmp(const void * const a, const void * const b) 83 { 84 return memcmp(a, b, sizeof (efi_guid_t)); 85 } 86diff --git a/src/include/efivar/efivar.h b/src/include/efivar/efivar.h 87index 316891c..ad6449d 100644 88--- a/src/include/efivar/efivar.h 89+++ b/src/include/efivar/efivar.h 90@@ -128,7 +128,7 @@ extern int efi_symbol_to_guid(const char *symbol, efi_guid_t *guid) 91 92 extern int efi_guid_is_zero(const efi_guid_t *guid); 93 extern int efi_guid_is_empty(const efi_guid_t *guid); 94-extern int efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b); 95+extern int efi_guid_cmp(const void * const a, const void * const b); 96 97 /* import / export functions */ 98 typedef struct efi_variable efi_variable_t; 99diff --git a/src/ucs2.h b/src/ucs2.h 100index dbb5900..edd8367 100644 101--- a/src/ucs2.h 102+++ b/src/ucs2.h 103@@ -23,16 +23,21 @@ 104 (((val) & ((mask) << (shift))) >> (shift)) 105 106 static inline size_t UNUSED 107-ucs2len(const uint16_t * const s, ssize_t limit) 108+ucs2len(const void *vs, ssize_t limit) 109 { 110 ssize_t i; 111- for (i = 0; i < (limit >= 0 ? limit : i+1) && s[i] != (uint16_t)0; i++) 112+ const uint16_t *s = vs; 113+ const uint8_t *s8 = vs; 114+ 115+ for (i = 0; 116+ i < (limit >= 0 ? limit : i+1) && s8[0] != 0 && s8[1] != 0; 117+ i++, s8 += 2, s++) 118 ; 119 return i; 120 } 121 122 static inline size_t UNUSED 123-ucs2size(const uint16_t * const s, ssize_t limit) 124+ucs2size(const void *s, ssize_t limit) 125 { 126 size_t rc = ucs2len(s, limit); 127 rc *= sizeof (uint16_t); 128@@ -69,10 +74,11 @@ utf8size(uint8_t *s, ssize_t limit) 129 } 130 131 static inline unsigned char * UNUSED 132-ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) 133+ucs2_to_utf8(const void * const voidchars, ssize_t limit) 134 { 135 ssize_t i, j; 136 unsigned char *ret; 137+ const uint16_t * const chars = voidchars; 138 139 if (limit < 0) 140 limit = ucs2len(chars, -1); 141@@ -124,10 +130,12 @@ ucs2_to_utf8(const uint16_t * const chars, ssize_t limit) 142 } 143 144 static inline ssize_t UNUSED NONNULL(4) 145-utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) 146+utf8_to_ucs2(void *ucs2void, ssize_t size, int terminate, uint8_t *utf8) 147 { 148 ssize_t req; 149 ssize_t i, j; 150+ uint16_t *ucs2 = ucs2void; 151+ uint16_t val16; 152 153 if (!ucs2 && size > 0) { 154 errno = EINVAL; 155@@ -162,10 +170,13 @@ utf8_to_ucs2(uint16_t *ucs2, ssize_t size, int terminate, uint8_t *utf8) 156 val = utf8[i] & 0x7f; 157 i += 1; 158 } 159- ucs2[j] = val; 160+ val16 = val; 161+ ucs2[j] = val16; 162+ } 163+ if (terminate) { 164+ val16 = 0; 165+ ucs2[j++] = val16; 166 } 167- if (terminate) 168- ucs2[j++] = (uint16_t)0; 169 return j; 170 }; 171 172-- 1732.20.1 174 175