diff options
author | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-12-07 01:28:27 +0059 |
---|---|---|
committer | Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> | 2011-12-17 12:05:45 +0059 |
commit | ce093aa6588813849e90b3b13068db26a432a3d3 (patch) | |
tree | e48717267b589870a7be2c0813a2cac0ec0320e4 | |
parent | caf08f71b824783dfe0ab57c6b639dca1106d695 (diff) | |
download | bionic-ce093aa6588813849e90b3b13068db26a432a3d3.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: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@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/net/getnameinfo.c | 15 | ||||
-rw-r--r-- | libc/netbsd/resolv/res_send.c | 33 |
8 files changed, 73 insertions, 52 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..0af7dd2d3 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 0f4e70c4b..756ee3fa5 100644 --- a/libc/bionic/system_properties.c +++ b/libc/bionic/system_properties.c @@ -158,7 +158,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; @@ -172,11 +175,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..ba24b6c5f 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 9a9f6e240..055e9f2f5 100644 --- a/libc/netbsd/gethnamaddr.c +++ b/libc/netbsd/gethnamaddr.c @@ -653,14 +653,14 @@ gethostbyaddr(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 ace8c1a4a..675cd08b9 100644 --- a/libc/netbsd/net/getaddrinfo.c +++ b/libc/netbsd/net/getaddrinfo.c @@ -408,7 +408,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; const char* cache_mode = getenv("ANDROID_DNS_MODE"); FILE* proxy = NULL; int success = 0; @@ -449,12 +452,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 -1; } @@ -1541,7 +1544,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/net/getnameinfo.c b/libc/netbsd/net/getnameinfo.c index d3d0011b9..dc7b5c863 100644 --- a/libc/netbsd/net/getnameinfo.c +++ b/libc/netbsd/net/getnameinfo.c @@ -139,7 +139,10 @@ android_gethostbyaddr_proxy(struct hostent* hp, const void *addr, socklen_t addr int sock; const int one = 1; - struct sockaddr_un proxy_addr; + union { + struct sockaddr_un un; + struct sockaddr generic; + } proxy_addr; const char* cache_mode = getenv("ANDROID_DNS_MODE"); FILE* proxy = NULL; int result = -1; @@ -167,11 +170,11 @@ android_gethostbyaddr_proxy(struct hostent* hp, const void *addr, socklen_t addr 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)); - if (TEMP_FAILURE_RETRY(connect(sock, (const struct sockaddr*) (void*) &proxy_addr, - sizeof(proxy_addr))) != 0) { + 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, &proxy_addr.generic, + sizeof(proxy_addr.un))) != 0) { close(sock); return -1; } diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c index b11895621..5aa888dce 100644 --- a/libc/netbsd/resolv/res_send.c +++ b/libc/netbsd/resolv/res_send.c @@ -396,7 +396,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) @@ -412,13 +415,13 @@ res_nsend(res_state statp, if (EXT(statp).nssocks[ns] == -1) continue; - peerlen = sizeof(peer); + peerlen = sizeof(peer.storage); if (getsockname(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; @@ -692,12 +695,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; } @@ -870,7 +876,10 @@ send_dg(res_state statp, int nsaplen; 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; @@ -976,9 +985,9 @@ send_dg(res_state statp, 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); @@ -1009,7 +1018,7 @@ send_dg(res_state statp, goto wait; } 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 |