0003-Fix-all-the-places-Werror-address-of-packed-member-c.patch 5.0 KB

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