[PATCH] Fix strict-aliasing warning in resolv/res_hconf.c

Paul Eggert eggert@cs.ucla.edu
Tue May 19 23:55:00 GMT 2015


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.



More information about the Libc-alpha mailing list