[EMAIL PROTECTED] wrote:

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;


Because if hdr->sipaddr is unaligned and the architecture doesn't support unaligned accesses, like many RISCs do, the result is undefined.

PS.
Haven't tested it, and dont now why one uses "struct ip_addr" and "struct ip_addr2"
DS.

Don't know that either.

Cheers,
Pedro Alves


/Beach/

On 4/18/06, Pedro Alves <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> 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
> [email protected] <mailto:[email protected]>
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>

------------------------------------------------------------------------

_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users




_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to