diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-07-29 09:26:16 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-07-29 09:26:16 +0000 |
commit | d86b92f399c4a5ed9f0629316277db8495527e2d (patch) | |
tree | ec22aa6b0b1fa09d2324a5a73435d189829a1647 /sys | |
parent | d1a81f7ad8f680a172a5183edfa04fca66d618dc (diff) |
be friendly with gcc-3.1.1 -O2, which takes advantage of ANSI C
pointer aliasing rule (gcc optimization/7427). from tsubai@netbsd, sync w/kame
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/in4_cksum.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sys/netinet/in4_cksum.c b/sys/netinet/in4_cksum.c index afea2d197ee..1717b216206 100644 --- a/sys/netinet/in4_cksum.c +++ b/sys/netinet/in4_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in4_cksum.c,v 1.5 2001/12/06 02:23:46 itojun Exp $ */ +/* $OpenBSD: in4_cksum.c,v 1.6 2002/07/29 09:26:15 itojun Exp $ */ /* $KAME: in4_cksum.c,v 1.10 2001/11/30 10:06:15 itojun Exp $ */ /* $NetBSD: in_cksum.c,v 1.13 1996/10/13 02:03:03 christos Exp $ */ @@ -100,8 +100,10 @@ in4_cksum(m, nxt, off, len) int sum = 0; int mlen = 0; int byte_swapped = 0; - struct ipovly ipov; - + union { + struct ipovly ipov; + u_int16_t w[10]; + } u; union { u_int8_t c[2]; u_int16_t s; @@ -117,12 +119,12 @@ in4_cksum(m, nxt, off, len) panic("in4_cksum: offset too short"); if (m->m_len < sizeof(struct ip)) panic("in4_cksum: bad mbuf chain"); - bzero(&ipov, sizeof(ipov)); - ipov.ih_len = htons(len); - ipov.ih_pr = nxt; - ipov.ih_src = mtod(m, struct ip *)->ip_src; - ipov.ih_dst = mtod(m, struct ip *)->ip_dst; - w = (u_int16_t *)&ipov; + bzero(&u.ipov, sizeof(u.ipov)); + u.ipov.ih_len = htons(len); + u.ipov.ih_pr = nxt; + u.ipov.ih_src = mtod(m, struct ip *)->ip_src; + u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst; + w = u.w; /* assumes sizeof(ipov) == 20 */ sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9]; |