From f36fbe8c85223def663f46499d0b6b9a75939aaa Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 14 Aug 2010 01:34:13 -0400 Subject: [PATCH] fix up strict-aliasing warnings Current build of some tools results in gcc warning about strict-aliasing violations. So change those freaky casts to memcpy's. When the pointer types work out, gcc will optimize this away anyways. Signed-off-by: Mike Frysinger --- ping6.c | 13 +++++++++---- tracepath.c | 2 +- tracepath6.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ping6.c b/ping6.c index c5ff881..86f9216 100644 --- a/ping6.c +++ b/ping6.c @@ -1104,18 +1104,21 @@ int build_niquery(__u8 *_nih) { struct ni_hdr *nih; int cc; + __u16 this_nonce; nih = (struct ni_hdr *)_nih; nih->ni_cksum = 0; - CLR(ntohs((*(__u16*)(nih->ni_nonce))) % mx_dup_ck); + memcpy(&this_nonce, &nih->ni_nonce, sizeof(this_nonce)); + CLR(ntohs(this_nonce) % mx_dup_ck); nih->ni_type = ICMPV6_NI_QUERY; cc = sizeof(*nih); datalen = 0; memcpy(nih->ni_nonce, ni_nonce, sizeof(nih->ni_nonce)); - *(__u16*)(nih->ni_nonce) = htons(ntransmitted + 1); + this_nonce = htons(ntransmitted + 1); + memcpy(&nih->ni_nonce, &this_nonce, sizeof(this_nonce)); nih->ni_code = ni_subject_type; nih->ni_qtype = htons(ni_query); @@ -1331,7 +1334,7 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv) #endif if (c->cmsg_len < CMSG_LEN(sizeof(int))) continue; - hops = *(int*)CMSG_DATA(c); + memcpy(&hops, CMSG_DATA(c), sizeof(int)); } } @@ -1355,7 +1358,9 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv) return 0; } else if (icmph->icmp6_type == ICMPV6_NI_REPLY) { struct ni_hdr *nih = (struct ni_hdr *)icmph; - __u16 seq = ntohs(*(__u16 *)nih->ni_nonce); + __u16 seq; + memcpy(&seq, &nih->ni_nonce, sizeof(seq)); + seq = ntohs(seq); if (memcmp(&nih->ni_nonce[2], &ni_nonce[2], sizeof(ni_nonce) - sizeof(__u16))) return 1; if (gather_statistics((__u8*)icmph, sizeof(*icmph), cc, diff --git a/tracepath.c b/tracepath.c index ca84a69..0a14b1b 100644 --- a/tracepath.c +++ b/tracepath.c @@ -142,7 +142,7 @@ restart: if (cmsg->cmsg_type == IP_RECVERR) { e = (struct sock_extended_err *) CMSG_DATA(cmsg); } else if (cmsg->cmsg_type == IP_TTL) { - rethops = *(int*)CMSG_DATA(cmsg); + memcpy(&rethops, CMSG_DATA(cmsg), sizeof(int)); } else { printf("cmsg:%d\n ", cmsg->cmsg_type); } diff --git a/tracepath6.c b/tracepath6.c index 5c2db8f..77a3563 100644 --- a/tracepath6.c +++ b/tracepath6.c @@ -170,7 +170,7 @@ restart: #ifdef IPV6_2292HOPLIMIT case IPV6_2292HOPLIMIT: #endif - rethops = *(int*)CMSG_DATA(cmsg); + memcpy(&rethops, CMSG_DATA(cmsg), sizeof(int)); break; default: printf("cmsg6:%d\n ", cmsg->cmsg_type); -- 1.7.1.1