[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH 1/1] [PATCH] udhcp: Fixed aliasing compilation error and alignment issues.
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2019-05-26 12:23:02
Message-ID: CAK1hOcMGgYmuYo1ZFv4p03UnrTU8bLookcpRB4x7QFzsSCTF6w () mail ! gmail ! com
[Download RAW message or body]

On Fri, May 24, 2019 at 12:51 PM Martin Lewis
<martin.lewis.x84@gmail.com> wrote:
> Fixed the compilation warning:
> networking/udhcp/d6_common.h:146:99: warning: dereferencing type-punned pointer \
> will break strict-aliasing rules [-Wstrict-aliasing] #define client6_data (*(struct \
> client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct \
> client6_data_t)])) ^
> Also fixed a possible alignment issue related to strict aliasing.
> 
> Signed-off-by: Martin Lewis <martin.lewis.x84@gmail.com>
> ---
> networking/udhcp/d6_common.h | 2 +-
> networking/udhcp/d6_dhcpc.c  | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h
> index 2178cb9..dee2558 100644
> --- a/networking/udhcp/d6_common.h
> +++ b/networking/udhcp/d6_common.h
> @@ -141,7 +141,7 @@ struct client6_data_t {
> unsigned env_idx;
> /* link-local IPv6 address */
> struct in6_addr ll_ip6;
> -};
> +} FIX_ALIASING;

Ok...

> --- a/networking/udhcp/d6_dhcpc.c
> +++ b/networking/udhcp/d6_dhcpc.c
> @@ -643,7 +643,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct \
> in6_addr *requested_ip client6_data.ia_na = xzalloc(len);
> client6_data.ia_na->code = D6_OPT_IA_NA;
> client6_data.ia_na->len = len - 4;
> -               *(uint32_t*)client6_data.ia_na->data = rand(); /* IAID */
> +               move_to_unaligned32(client6_data.ia_na->data, rand());
> if (requested_ipv6) {
> struct d6_option *iaaddr = (void*)(client6_data.ia_na->data + 4+4+4);
> iaaddr->code = D6_OPT_IAADDR;
> @@ -661,7 +661,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct \
> in6_addr *requested_ip client6_data.ia_pd = xzalloc(len);
> client6_data.ia_pd->code = D6_OPT_IA_PD;
> client6_data.ia_pd->len = len - 4;
> -               *(uint32_t*)client6_data.ia_pd->data = rand(); /* IAID */
> +               move_to_unaligned32(client6_data.ia_pd->data, rand());
> opt_ptr = mempcpy(opt_ptr, client6_data.ia_pd, len);
> }

Well, ia_na->data[] *is* 4-byte aligned.
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic