This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
- From: Steve Ellcey <sellcey at imgtec dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: Pedro Alves <palves at redhat dot com>, Andreas Schwab <schwab at suse dot de>, "Roland McGrath" <roland at hack dot frob dot com>, Paul Eggert <eggert at cs dot ucla dot edu>, <libc-alpha at sourceware dot org>
- Date: Thu, 28 May 2015 09:00:42 -0700
- Subject: Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
- Authentication-results: sourceware.org; auth=none
- References: <5bfa6373-3817-4d31-a5ee-a8676e79b723 at BAMAIL02 dot ba dot imgtec dot org> <555BB55E dot 3050304 at cs dot ucla dot edu> <1432075989 dot 16668 dot 62 dot camel at ubuntu-sellcey> <555BC19B dot 90001 at cs dot ucla dot edu> <1432077972 dot 16668 dot 65 dot camel at ubuntu-sellcey> <20150519235817 dot 9516F2C3A73 at topped-with-meat dot com> <555C3E0B dot 2040404 at redhat dot com> <mvma8wzbqsv dot fsf at hawking dot suse dot de> <555C48F0 dot 2030208 at redhat dot com> <1432139240 dot 16668 dot 77 dot camel at ubuntu-sellcey> <55658C2A dot 70209 at redhat dot com> <5565B4D3 dot 3090401 at redhat dot com>
- Reply-to: <sellcey at imgtec dot com>
OK, so here is a complete patch based on Pedro's proposal. It compiles
fine for me on MIPS with the latest GCC. OK to checkin?
Steve Ellcey
sellcey@imgtec.com
2015-05-28 Steve Ellcey <sellcey@imgtec.com>
* resolv/res_hconf.c (_res_hconf_reorder_addrs): Use a union to
copy data from cur_ifr->ifr_addr.
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index 73942e8..b9c423e 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -410,6 +410,11 @@ _res_hconf_reorder_addrs (struct hostent *hp)
int sd, num, i;
/* Save errno. */
int save = errno;
+ union
+ {
+ struct sockaddr sa;
+ struct sockaddr_in sin;
+ } ss;
/* Initialize interface table. */
@@ -443,14 +448,14 @@ _res_hconf_reorder_addrs (struct hostent *hp)
continue;
ifaddrs[new_num_ifs].addrtype = AF_INET;
- ifaddrs[new_num_ifs].u.ipv4.addr =
- ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr;
+ ss.sa = cur_ifr->ifr_addr;
+ ifaddrs[new_num_ifs].u.ipv4.addr = ss.sin.sin_addr.s_addr;
if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0)
continue;
- ifaddrs[new_num_ifs].u.ipv4.mask =
- ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr;
+ ss.sa = cur_ifr->ifr_netmask;
+ ifaddrs[new_num_ifs].u.ipv4.mask = ss.sin.sin_addr.s_addr;
/* Now we're committed to this entry. */
++new_num_ifs;