[prev in list] [next in list] [prev in thread] [next in thread]
List: glibc-alpha
Subject: Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c
From: Florian Weimer <fweimer () redhat ! com>
Date: 2015-05-27 11:16:46
Message-ID: 5565A79E.6010403 () redhat ! com
[Download RAW message or body]
On 05/27/2015 01:09 PM, Pedro Alves wrote:
> On 05/27/2015 11:50 AM, Florian Weimer wrote:
>> On 05/27/2015 11:19 AM, Pedro Alves wrote:
>>> 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?
>>
>> I think it's still undefined behavior.
>
> How so? AFAIK, it's implementation defined, and GCC allows type-punning provided
> the memory is accessed through the union type.
>
> https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/Optimize-Options.html#Type-punning
You mean, copy it to a union member of type struct sockaddr, and reading
from that union as struct sockaddr_in?
(Based on my reading of the standard, memcpy does not change effective
type if one has been assigned.)
--
Florian Weimer / Red Hat Product Security
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic