[PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
Steve Ellcey
sellcey@imgtec.com
Wed May 20 02:32:00 GMT 2015
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
More information about the Libc-alpha
mailing list