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: Paul Eggert <eggert at cs dot ucla dot edu>
- Cc: <libc-alpha at sourceware dot org>
- Date: Tue, 19 May 2015 16:26:12 -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>
- Reply-to: <sellcey at imgtec dot com>
On Tue, 2015-05-19 at 16:04 -0700, Paul Eggert wrote:
> On 05/19/2015 03:53 PM, Steve Ellcey wrote:
> > + union
> > + {
> > + struct sockaddr *sa;
> > + struct sockaddr_in *sin;
> > + } ss;
> > int sd, num, i;
> > /* Save errno. */
> > int save = errno;
> > @@ -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;
>
> I'm afraid that's no better than casting. It needs to be a union of
> contents, not of pointers.
Hm, I am not sure I know how to do that. I tried changing
sysdeps/gnu/net/if.h to include a 'struct sockaddr_in ifru_addr_in;'
entry in the ifru_data union but that won't compile.
In file included from ../include/net/if.h:3:0,
from ../sysdeps/generic/ifreq.h:22,
from ../sysdeps/unix/sysv/linux/ifreq.c:19:
../sysdeps/gnu/net/if.h:142:21: error: field 'ifru_addr_in' has
incomplete type
struct sockaddr_in ifru_addr_in;
I am not sure if I am just missing an include or if I simply cannot use
the sockaddr_in struct in this header.
Steve Ellcey
sellcey@imgtec.com