lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] [PATCH] fix warning for gcc and possible unaligned acce


From: beach . dk
Subject: Re: [lwip-users] [PATCH] fix warning for gcc and possible unaligned access
Date: Tue, 18 Apr 2006 13:40:45 +0200

Hi,
 
Why not just replace the lines
*(struct ip_addr2 *)&sipaddr = hdr->sipaddr;
*(struct ip_addr2 *)&dipaddr = hdr->dipaddr;
with
sipaddr = *(struct ip_addr *)&hdr->sipaddr;
dipaddr = *(struct ip_addr *)&hdr->dipaddr;
PS.
Haven't tested it, and dont now why one uses "struct ip_addr" and "struct ip_addr2"
DS.

/Beach/
 
 


On 4/18/06, Pedro Alves <address@hidden> wrote:
> This patch fixes this catched by gcc:
>
> $ make
> (...)/lwip/src/netif/etharp.c
> (...)/lwip/src/netif/etharp.c: In function 'etharp_arp_input':
> (...)/lwip/src/netif/etharp.c:505: warning: dereferencing type-punned
> pointer will break strict-aliasing rules
> (...)/lwip/src/netif/etharp.c:506: warning: dereferencing type-punned
> pointer will break strict-aliasing rules
>
> We could also use memcpy here, but that seems overkill for copying 8 bytes.
>
> Cheers,
> Pedro Alves
>
> Index: src/netif/etharp.c
> ===================================================================
> RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
> retrieving revision 1.94
> diff -u -r1.94 etharp.c
> --- src/netif/etharp.c    29 Mar 2006 13:16:40 -0000    1.94
> +++ src/netif/etharp.c    18 Apr 2006 10:41:47 -0000
> @@ -487,10 +487,11 @@
>   }
>
>   hdr = p->payload;
> -
>   /* get aligned copies of addresses */
> -  *(struct ip_addr2 *)&sipaddr = hdr->sipaddr;
> -  *(struct ip_addr2 *)&dipaddr = hdr->dipaddr;
> +  for(i=0; i<sizeof(hdr->sipaddr); i++)
> +    ((u8_t*)&sipaddr)[i] = ((u8_t*)&hdr->sipaddr)[i];
> +  for(i=0; i<sizeof(hdr->dipaddr); i++)
> +    ((u8_t*)&dipaddr)[i] = ((u8_t*)&hdr->dipaddr)[i];
>
>   /* this interface is not configured? */
>   if (netif->ip_addr.addr == 0) {
>
>
>
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>

 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]