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

Lennart Poettering lennart at poettering.net
Sun Apr 12 12:43:10 PDT 2015


On Wed, 11.03.15 08:13, Shawn Landden (shawn at churchofgit.com) wrote:

> 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)

Hmm? uint64_t works fine on 32bit too. The compiler can do the
necessary emulation on its own... I don't see the need to change
anything here.

> 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
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list