ip(6)_tables.h: return type difference in ip(6)t_get_target

Henning Peters hpeters at math.uni-goettingen.de
Fri Sep 9 12:02:38 CEST 2005


Hi Patrick,
yes, you are right. Thank you for the pointer and example code.

return (struct ip6t_entry_target *) ((void *)e + e->target_offset);

seems ugly, but necessary if compilers are more strict to match the return
type. I would appreciate if this could be applied in order to faciliate
C++/iptables development. I am not sure whether other C compilers might
not see this issue aswell?!

Henning


Patrick Schaaf sagte Fr, 9.09.2005, 11:03:
>>> Back to my original post: Is there a reason not to change the code as I
>>> proposed?
>>
>> Your code change is wrong. See below for proof code. Remember that
>> a "pointer + integer" always advances the pointer according to the
>> type of the thing pointed to, i.e. by "integer*sizeof(*pointer)".
>> And casting seems to have precedence over "+"...
>
> Damn, my proof code was nonsensical in that it not tested for the
> "casting seems to" property. Corrected code below. So, casting
> has higher precedence than "+". Which does not make your proposed
> change more correct, it's just wrong in a different way :)
>
> best regards
>   Patrick
>
> $ cat foo.c
> struct foo { int a; };
> struct bar { int a; int b; };
>
> int main(int argc, char **argv)
> {
>         struct foo fooarray[10];
>         struct foo *bar = fooarray;
>
>         printf("struct foo *: %p %p\n", bar, bar + 1);
>         printf("struct bar *: %p %p\n", bar, (struct bar *) bar + 1);
>         printf("void *: %p %p\n", bar, (void *) bar + 1);
>         return 0;
> }
> $ gcc -o foo foo.c
> $ ./foo
> struct foo *: 0xbffff878 0xbffff87c
> struct bar *: 0xbffff878 0xbffff880
> void *: 0xbffff878 0xbffff879
>
>






More information about the netfilter-devel mailing list