From patchwork Tue May 19 22:53:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 6805 Received: (qmail 18552 invoked by alias); 19 May 2015 22:54:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 18539 invoked by uid 89); 19 May 2015 22:54:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Message-ID: <1432075989.16668.62.camel@ubuntu-sellcey> Subject: Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c From: Steve Ellcey Reply-To: To: Paul Eggert CC: Date: Tue, 19 May 2015 15:53:09 -0700 In-Reply-To: <555BB55E.3050304@cs.ucla.edu> References: <5bfa6373-3817-4d31-a5ee-a8676e79b723@BAMAIL02.ba.imgtec.org> <555BB55E.3050304@cs.ucla.edu> MIME-Version: 1.0 On Tue, 2015-05-19 at 15:12 -0700, Paul Eggert wrote: > On 05/19/2015 02:09 PM, Steve Ellcey wrote: > > 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. > > It's warning about a portability problem that seems to be genuine. Can't > we fix the problem using a union as before? That should be better than > trying to fool GCC into not warning about the problem. OK, how is this version with no casts. Steve Ellcey sellcey@imgtec.com 2015-05-19 Steve Ellcey * resolv/res_hconf.c (_res_hconf_reorder_addrs): Split up assignment and use union to avoid GCC strict aliasing warning. diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c index 73942e8..0dbee2e 100644 --- a/resolv/res_hconf.c +++ b/resolv/res_hconf.c @@ -407,6 +407,11 @@ _res_hconf_reorder_addrs (struct hostent *hp) if (num_ifs <= 0) { struct ifreq *ifr, *cur_ifr; + 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; 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; + ss.sa = &cur_ifr->ifr_netmask; + ifaddrs[new_num_ifs].u.ipv4.mask = ss.sin->sin_addr.s_addr; /* Now we're committed to this entry. */ ++new_num_ifs;