[PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
Pedro Alves
palves@redhat.com
Wed May 27 11:00:00 GMT 2015
On 05/20/2015 05:27 PM, Steve Ellcey wrote:
> diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
> index 73942e8..3b05287 100644
> --- a/resolv/res_hconf.c
> +++ b/resolv/res_hconf.c
> @@ -444,13 +444,13 @@ _res_hconf_reorder_addrs (struct hostent *hp)
>
> 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;
> + cur_ifr->ifr_addr_in.sin_addr.s_addr;
Without adding a new union member, isn't the simplest to just take a
copy step? The interface already clearly assumes that a sockaddr_in
fits in a sockaddr. Something like:
union
{
struct sockaddr sa;
struct sockaddr_in sin;
} ss;
- 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;
etc. Maybe the compiler even elides the copying. (And if it doesn't,
would it matter here?)
Thanks,
Pedro Alves
More information about the Libc-alpha
mailing list