Re: [PATCH] netlink: fix gcc -Wconversion compilation warning

From: Eric W. Biederman
Date: Sat Dec 18 2010 - 01:58:29 EST


David Miller <davem@xxxxxxxxxxxxx> writes:

> From: ebiederm@xxxxxxxxxxxx (Eric W. Biederman)
> Date: Mon, 13 Dec 2010 13:35:25 -0800
>
>> "Kirill A. Shutsemov" <kirill@xxxxxxxxxxxxx> writes:
>>
>>> From: Dmitry V. Levin <ldv@xxxxxxxxxxxx>
>>>
>>> $ cat << EOF | gcc -Wconversion -xc -S -o/dev/null -
>>> unsigned f(void) {return NLMSG_HDRLEN;}
>>> EOF
>>> <stdin>: In function 'f':
>>> <stdin>:3:26: warning: negative integer implicitly converted to unsigned type
>>>
>> This doesn't look like a bad fix, but I believe things will fail if
>> we give NLMSG_ALIGN an unsigned long like size_t. Say like sizeof.
>
> What are you talking about? That's exactly his test case,
> look at what NLMSG_HDRLEN is defined to, it's exactly the
> case you're worried "will fail", it passes sizeof() to
> NLMSG_ALIGN.
>
> I think I'll apply Kirill's original patch, it's good enough
> and simpler.

Probably. The case I was worried about was masks that become
0xffffffxx on 64bit instead of 0xffffffffffffxx. Especially
when mixing those with ints.

It is possible to get some really weird things.

Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/