[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xinetd
Subject:    Re: [xinetd] bug in addrlist_match (with IPv6 addresses)
From:       Matthias Andree <ma+xi () dt ! e-technik ! uni-dortmund ! de>
Date:       2003-08-07 8:39:34
[Download RAW message or body]

Steve G <linux_4ever@yahoo.com> writes:

>>>Probably the most portable way to do it is to make a
> macro
>>>
>>> #define IPV4_ADDR_OFFSET (a) ((__const uint32_t *)
> (a))[3]
>>
>>One-word interjection: Ugh.
>
> Right. :)
>
>> -  uint32_t *tmp_addr = (unsigned *)&addr->sa_data[3];
>> +  uint32_t *tmp_addr =
>> &SAIN6(addr)->sin6_addr.s6_addr32[3];
>
> I think I see what the problem is...missing parenthesis. It
> should have been: 
>
> uint32_t *tmp_addr = ((unsigned *)&addr->sa_data)[3];

Neither. You don't assign (((unsigned *)X)[N]) to uint32_t because you
don't know if sizeof unsigned == sizeof uint32_t. There's a reason why
these exist.

Besides, I'd personally add another pair of parentheses around the
IPV4_ADDR_OFFSET expansion so you don't leave a dangling [3] in the air
-- aside from disliking macros because they defeat type checking and
cause non-obvious errors to show up at strange places.

-- 
Matthias Andree
_______________________________________________
xinetd mailing list
xinetd@xinetd.org
http://www.xinetd.org/mailman/listinfo/xinetd
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic