diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2013-07-25 10:10:44 +0530 |
---|---|---|
committer | Amit Pundir <amit.pundir@linaro.org> | 2013-07-25 10:10:44 +0530 |
commit | f3da0666381c671edb7f7dd8da7c6e3f8cec84d5 (patch) | |
tree | 5b1abd0f8fd1fbff7e952dca61e1e8c2eb329b83 | |
parent | d146e8e4e922aa272aa4c088fd6122836c8f45ca (diff) | |
download | bionic-f3da0666381c671edb7f7dd8da7c6e3f8cec84d5.tar.gz |
bionic: Fix aliasing violations
This makes bionic compile with compilers enforcing
strict adherence to aliasing rules (e.g. gcc 4.6+
with -Wstrict-aliasing=2 -Werror=strict-aliasing).
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
-rw-r--r-- | libc/bionic/md5.c | 2 | ||||
-rw-r--r-- | libc/bionic/md5.h | 5 | ||||
-rw-r--r-- | libc/bionic/system_properties.c | 11 | ||||
-rw-r--r-- | libc/include/netinet/in6.h | 34 | ||||
-rw-r--r-- | libc/netbsd/gethnamaddr.c | 8 | ||||
-rw-r--r-- | libc/netbsd/net/getaddrinfo.c | 17 | ||||
-rw-r--r-- | libc/netbsd/resolv/res_send.c | 31 |
7 files changed, 64 insertions, 44 deletions
diff --git a/libc/bionic/md5.c b/libc/bionic/md5.c index ba4aaed22..02785bdaa 100644 --- a/libc/bionic/md5.c +++ b/libc/bionic/md5.c @@ -231,7 +231,7 @@ MD5_Update (struct md5 *m, const void *v, size_t len) } calc(m, current); #else - calc(m, (u_int32_t*)m->save); + calc(m, m->save32); #endif offset = 0; } diff --git a/libc/bionic/md5.h b/libc/bionic/md5.h index a381994ef..3b0a2511b 100644 --- a/libc/bionic/md5.h +++ b/libc/bionic/md5.h @@ -40,7 +40,10 @@ struct md5 { unsigned int sz[2]; u_int32_t counter[4]; - unsigned char save[64]; + union { + unsigned char save[64]; + u_int32_t save32[16]; + }; }; typedef struct md5 MD5_CTX; diff --git a/libc/bionic/system_properties.c b/libc/bionic/system_properties.c index 0587430a5..3fadba2cd 100644 --- a/libc/bionic/system_properties.c +++ b/libc/bionic/system_properties.c @@ -197,7 +197,10 @@ int __system_property_get(const char *name, char *value) static int send_prop_msg(prop_msg *msg) { struct pollfd pollfds[1]; - struct sockaddr_un addr; + union { + struct sockaddr_un addr; + struct sockaddr addr_g; + } addr; socklen_t alen; size_t namelen; int s; @@ -211,11 +214,11 @@ static int send_prop_msg(prop_msg *msg) memset(&addr, 0, sizeof(addr)); namelen = strlen(property_service_socket); - strlcpy(addr.sun_path, property_service_socket, sizeof addr.sun_path); - addr.sun_family = AF_LOCAL; + strlcpy(addr.addr.sun_path, property_service_socket, sizeof addr.addr.sun_path); + addr.addr.sun_family = AF_LOCAL; alen = namelen + offsetof(struct sockaddr_un, sun_path) + 1; - if(TEMP_FAILURE_RETRY(connect(s, (struct sockaddr *) &addr, alen)) < 0) { + if(TEMP_FAILURE_RETRY(connect(s, &addr.addr_g, alen) < 0)) { close(s); return result; } diff --git a/libc/include/netinet/in6.h b/libc/include/netinet/in6.h index 7f3286ae9..c8ba133de 100644 --- a/libc/include/netinet/in6.h +++ b/libc/include/netinet/in6.h @@ -31,28 +31,28 @@ #include <linux/in6.h> #define IN6_IS_ADDR_UNSPECIFIED(a) \ - ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == 0)) + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] == 0)) #define IN6_IS_ADDR_LOOPBACK(a) \ - ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1))) + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] == ntohl(1))) #define IN6_IS_ADDR_V4COMPAT(a) \ - ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1))) + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == 0) && \ + ((a)->s6_addr32[3] != 0) && \ + ((a)->s6_addr32[3] != ntohl(1))) #define IN6_IS_ADDR_V4MAPPED(a) \ - ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ - (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) + (((a)->s6_addr32[0] == 0) && \ + ((a)->s6_addr32[1] == 0) && \ + ((a)->s6_addr32[2] == ntohl(0x0000ffff))) #define IN6_IS_ADDR_LINKLOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) @@ -65,7 +65,7 @@ (((a)->s6_addr[0] & 0xfe) == 0xfc) #define IN6_IS_ADDR_MULTICAST(a) \ - (((__const uint8_t *) (a))[0] == 0xff) + ((a)->s6_addr[0] == 0xff) #define IPV6_ADDR_SCOPE_NODELOCAL 0x01 diff --git a/libc/netbsd/gethnamaddr.c b/libc/netbsd/gethnamaddr.c index ee5052e4c..62144675e 100644 --- a/libc/netbsd/gethnamaddr.c +++ b/libc/netbsd/gethnamaddr.c @@ -824,14 +824,14 @@ android_gethostbyaddrforiface_real(const void *addr, assert(addr != NULL); if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr *)(const void *)uaddr) || - IN6_IS_ADDR_SITELOCAL((const struct in6_addr *)(const void *)uaddr))) { + (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr *)addr) || + IN6_IS_ADDR_SITELOCAL((const struct in6_addr *)addr))) { h_errno = HOST_NOT_FOUND; return NULL; } if (af == AF_INET6 && len == IN6ADDRSZ && - (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)(const void *)uaddr) || - IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)(const void *)uaddr))) { + (IN6_IS_ADDR_V4MAPPED((const struct in6_addr *)addr) || + IN6_IS_ADDR_V4COMPAT((const struct in6_addr *)addr))) { /* Unmap. */ addr += IN6ADDRSZ - INADDRSZ; uaddr += IN6ADDRSZ - INADDRSZ; diff --git a/libc/netbsd/net/getaddrinfo.c b/libc/netbsd/net/getaddrinfo.c index 401bc6efc..9d8314b8c 100644 --- a/libc/netbsd/net/getaddrinfo.c +++ b/libc/netbsd/net/getaddrinfo.c @@ -410,7 +410,10 @@ android_getaddrinfo_proxy( { int sock; const int one = 1; - struct sockaddr_un proxy_addr; + union { + struct sockaddr_un un; + struct sockaddr generic; + } proxy_addr; FILE* proxy = NULL; int success = 0; @@ -434,12 +437,12 @@ android_getaddrinfo_proxy( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); memset(&proxy_addr, 0, sizeof(proxy_addr)); - proxy_addr.sun_family = AF_UNIX; - strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd", - sizeof(proxy_addr.sun_path)); + proxy_addr.un.sun_family = AF_UNIX; + strlcpy(proxy_addr.un.sun_path, "/dev/socket/dnsproxyd", + sizeof(proxy_addr.un.sun_path)); if (TEMP_FAILURE_RETRY(connect(sock, - (const struct sockaddr*) &proxy_addr, - sizeof(proxy_addr))) != 0) { + &proxy_addr.generic, + sizeof(proxy_addr.un))) != 0) { close(sock); return EAI_NODATA; } @@ -1536,7 +1539,7 @@ _get_scope(const struct sockaddr *addr) /* RFC 4380, section 2.6 */ #define IN6_IS_ADDR_TEREDO(a) \ - ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == ntohl(0x20010000))) + (((a)->s6_addr32[0]) == ntohl(0x20010000)) /* RFC 3056, section 2. */ #define IN6_IS_ADDR_6TO4(a) \ diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c index d407ac8c8..0293af6cf 100644 --- a/libc/netbsd/resolv/res_send.c +++ b/libc/netbsd/resolv/res_send.c @@ -418,6 +418,10 @@ res_nsend(res_state statp, if (EXT(statp).nscount != 0) { int needclose = 0; struct sockaddr_storage peer; + union { + struct sockaddr_storage storage; + struct sockaddr generic; + } peer; socklen_t peerlen; if (EXT(statp).nscount != statp->nscount) @@ -433,13 +437,13 @@ res_nsend(res_state statp, if (EXT(statp).nssocks[ns] == -1) continue; - peerlen = sizeof(peer); + peerlen = sizeof(peer.storage); if (getpeername(EXT(statp).nssocks[ns], - (struct sockaddr *)(void *)&peer, &peerlen) < 0) { + &peer.generic, &peerlen) < 0) { needclose++; break; } - if (!sock_eq((struct sockaddr *)(void *)&peer, + if (!sock_eq(&peer.generic, get_nsaddr(statp, (size_t)ns))) { needclose++; break; @@ -760,12 +764,15 @@ send_vc(res_state statp, /* Are we still talking to whom we want to talk to? */ if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { - struct sockaddr_storage peer; - socklen_t size = sizeof peer; + union { + struct sockaddr_storage storage; + struct sockaddr generic; + } peer; + socklen_t size = sizeof peer.storage; if (getpeername(statp->_vcsock, - (struct sockaddr *)(void *)&peer, &size) < 0 || - !sock_eq((struct sockaddr *)(void *)&peer, nsap)) { + &peer.generic, &size) < 0 || + !sock_eq(&peer.generic, nsap)) { res_nclose(statp); statp->_flags &= ~RES_F_VC; } @@ -1044,6 +1051,10 @@ send_dg(res_state statp, struct timespec now, timeout, finish; fd_set dsmask; struct sockaddr_storage from; + union { + struct sockaddr_storage storage; + struct sockaddr generic; + } from; socklen_t fromlen; int resplen, seconds, n, s; @@ -1135,9 +1146,9 @@ retry: return (0); } errno = 0; - fromlen = sizeof(from); + fromlen = sizeof(from.storage); resplen = recvfrom(s, (char*)ans, (size_t)anssiz,0, - (struct sockaddr *)(void *)&from, &fromlen); + &from.generic, &fromlen); if (resplen <= 0) { Perror(statp, stderr, "recvfrom", errno); res_nclose(statp); @@ -1171,7 +1182,7 @@ retry: goto retry; } if (!(statp->options & RES_INSECURE1) && - !res_ourserver_p(statp, (struct sockaddr *)(void *)&from)) { + !res_ourserver_p(statp, &from.generic)) { /* * response from wrong server? ignore it. * XXX - potential security hazard could |