On 01/10/2010 02:39 PM, Paul Koning wrote:
>> ...
>> typedef unsigned char uint8_t;
>> typedef unsigned int uint32_t;
>>
>> struct in6_addr
>> {
>> uint8_t __s6_addr[16];
>> };
>>
>> static inline int
>> address_in_use (unsigned char *a, struct in6_addr *in6)
>> {
>> if ((((const uint32_t *)(a))[0]
>> == ((const uint32_t *)(in6->__s6_addr))[0]
>> && ((const uint32_t *)(a))[1]
>> == ((const uint32_t *)(in6->__s6_addr))[1]
>> && ((const uint32_t *)(a))[2]
>> == ((const uint32_t *)(in6->__s6_addr))[2]
>> && ((const uint32_t *)(a))[3]
>> == ((const uint32_t *)(in6->__s6_addr))[3]))
>> return 1;
>>
>> return 0;
>> }
>
> That code seems to be broken for reasons other than aliasing -- it can
> easily give alignment errors on platforms that require natural alignment
> (because an in6_addr object might be allocated at an odd address).
It that case, the allocator would be broken. But the breakage isn't
here, it's in the allocator. I don't think there's anything wrong
with this code.
Andrew.