« Return to Thread: [PATCH] Fix aliasing violation.

Re: [PATCH] Fix aliasing violation.

by David Woodhouse :: Rate this Message:

Reply to Author | View in Thread

On Fri, 2008-10-03 at 16:43 +0200, goldsimon@... wrote:
> In 1.3.0, we converted all calls to 'memcpy' to either 'MEMCPY' or
> 'SMEMCPY' (s for short). The goal is optimization: SMEMCPY is defined to
> memcpy (which the compiler may inline e.g. if size is known at compile
> time and small); whil MEMCPY can be overridden to provide a better copy
> mechanism (on my platform, for example, copying non-aligned data can be
> solved much better when loading full words and shifting in registers).
>
> Therfore, using 'memcpy' directly should be avoided: when you know your
> compiler can't optimize it, you can redefine SMEMCPY to inlining yourself.

I'm inclined to suggest that the correct answer in that case is to _fix_
the compiler, not work around it. But OK...

Index: src/netif/etharp.c
===================================================================
RCS file: /sources/lwip/lwip/src/netif/etharp.c,v
retrieving revision 1.148
diff -u -p -r1.148 etharp.c
--- src/netif/etharp.c 19 Jun 2008 16:40:59 -0000 1.148
+++ src/netif/etharp.c 3 Oct 2008 14:49:57 -0000
@@ -705,7 +705,7 @@ etharp_arp_input(struct netif *netif, st
       hdr->opcode = htons(ARP_REPLY);
 
       hdr->dipaddr = hdr->sipaddr;
-      hdr->sipaddr = *(struct ip_addr2 *)&netif->ip_addr;
+      SMEMCPY(&hdr->sipaddr, &netif->ip_addr, sizeof(hdr->sipaddr));
 
       LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
                   (netif->hwaddr_len == ETHARP_HWADDR_LEN));


--
David Woodhouse                            Open Source Technology Centre
David.Woodhouse@...                              Intel Corporation



_______________________________________________
lwip-devel mailing list
lwip-devel@...
http://lists.nongnu.org/mailman/listinfo/lwip-devel

 « Return to Thread: [PATCH] Fix aliasing violation.