Source-Changes archive

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

Re: CVS commit: src/sys/netinet6



> On Mon, Mar 10, 2008 at 08:22:36AM +0900, YAMAMOTO Takashi wrote:
> > if so, the use of (uint16_t *) isn't safe either, is it?
> 
> The address is computed explicitly as byte address and w is only
> dereferenced later if it is correctly aligned.
> 
> Joerg

what you concern about is the -> operator, not the types of the pointers?

it the following one ok?

YAMAMOTO Takashi


Index: in6_cksum.c
===================================================================
RCS file: /cvsroot/src/sys/netinet6/in6_cksum.c,v
retrieving revision 1.25
diff -u -p -r1.25 in6_cksum.c
--- in6_cksum.c 9 Mar 2008 22:05:50 -0000       1.25
+++ in6_cksum.c 10 Mar 2008 00:53:56 -0000
@@ -58,6 +58,7 @@ in6_cksum(struct mbuf *m, u_int8_t nxt, 
        const struct ip6_hdr *ip6;
        uint32_t sum;
        const uint16_t *w;
+       const char *cp;
 
        if (__predict_false(off < sizeof(struct ip6_hdr)))
                panic("in6_cksum: offset too short for IPv6 header");
@@ -86,8 +87,9 @@ in6_cksum(struct mbuf *m, u_int8_t nxt, 
 #else
        sum = (len & 0xffff) + ((len >> 16) & 0xffff) + nxt;
 #endif
-       ip6 = mtod(m, const struct ip6_hdr *);
-       w = (const uint16_t *)(const void *)&ip6->ip6_src;
+       cp = mtod(m, const char *);
+       w = (const uint16_t *)(cp + offsetof(struct ip6_hdr, ip6_src));
+       ip6 = (const void *)cp;
        if (__predict_true((uintptr_t)w % 2 == 0)) {
                in6_src = &ip6->ip6_src;
                in6_dst = &ip6->ip6_dst;


Home | Main Index | Thread Index | Old Index