[systemd-devel] [PATCH 5/6] network: fix strict aliasing issue

Shawn Landden shawn at churchofgit.com
Wed Mar 11 08:13:48 PDT 2015


We shouldn't assume 64-bit arch with the way we do math either.
(although I will submit a patch to glibc to add a uint64_t union alias)
---
 src/network/networkd-address.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 0be6165..4b7f451 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -605,12 +605,12 @@ bool address_equal(Address *a1, Address *a2) {
                 }
 
         case AF_INET6: {
-                uint64_t *b1, *b2;
+                uint32_t *b1, *b2;
 
-                b1 = (uint64_t*)&a1->in_addr.in6;
-                b2 = (uint64_t*)&a2->in_addr.in6;
+                b1 = &a1->in_addr.in6.s6_addr32[0];
+                b2 = &a2->in_addr.in6.s6_addr32[0];
 
-                return (((b1[0] ^ b2[0]) | (b1[1] ^ b2[1])) == 0UL);
+                return (((b1[0] ^ b2[0]) | (b1[1] ^ b2[1]) | (b1[2] ^ b2[2]) | (b1[3] ^  b2[3])) == 0);
         }
 
         default:
-- 
2.2.1.209.g41e5f3a



More information about the systemd-devel mailing list