This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Here is a patch to clean up the strict-aliasing warning that we get
when compiling resolv/res_hconf.c with the latest top-of-tree GCC.
It uses the same casts as before but splits up the assignment into
two parts and that seems to be sufficient to get rid of the GCC
warning.

Is this OK to checkin?

Steve Ellcey
sellcey@imgtec.com


2015-05-19  Steve Ellcey  <sellcey@imgtec.com>

	* resolv/res_hconf.c (_res_hconf_reorder_addrs): Split up assignments
	to avoid GCC strict aliasing warning.


diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index 73942e8..c1c542a 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -407,6 +407,7 @@ _res_hconf_reorder_addrs (struct hostent *hp)
   if (num_ifs <= 0)
     {
       struct ifreq *ifr, *cur_ifr;
+      struct sockaddr_in *sin;
       int sd, num, i;
       /* Save errno.  */
       int save = errno;
@@ -443,14 +444,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;
+	      sin = (struct sockaddr_in *) &cur_ifr->ifr_addr;
+	      ifaddrs[new_num_ifs].u.ipv4.addr = 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;
+	      sin = (struct sockaddr_in *) &cur_ifr->ifr_netmask;
+	      ifaddrs[new_num_ifs].u.ipv4.mask = sin->sin_addr.s_addr;
 
 	      /* Now we're committed to this entry.  */
 	      ++new_num_ifs;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]