Re: [PATCH] Don't compare unsigned variable for <0 in sys_prctl()





On Tue, 28 Nov 2006, Jesper Juhl wrote:

In kernel/sys.c::sys_prctl() the argument named 'arg2' is very clearly
of type 'unsigned long', and when compiling with "gcc -W" gcc also warns :
kernel/sys.c:2089: warning: comparison of unsigned expression < 0 is always false

So this patch removes the test of "arg2 < 0".

No, we don't do this.

This is why we don't compile with "-W". Gcc is crap.

The fact is, if it's unsigned, it's not something that the programmer
should have to care about. We should write our code to be readable and
obviously safe, and that means that

if (x < 0 || x > MAX)
return -ERROR;

is the _right_ way to do things, without having to carry stupid context
around in our heads.

If the compiler (whose _job_ it is to carry all that context and use it to
generate good code) notices that the fact that "x" is unsignes means that
one of the tests is unnecessary, that does not make it wrong.

Gcc warns for a lot of wrong things. This is one of them.

Friends don't let friends use "-W".

Linus
-
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/



Relevant Pages

  • Re: [PATCH] Dont compare unsigned variable for <0 in sys_prctl()
    ... This is why we don't compile with "-W". ... is the _right_ way to do things, without having to carry stupid context ... generate good code) notices that the fact that "x" is unsignes means that ... Friends don't let friends use "-W". ...
    (Linux-Kernel)
  • Re: C container and persistent library ?
    ... (you wont win friends here by implying that C is an inferior cousin to ... Try gcc then. ...
    (comp.lang.c)
  • [PATCH] Makefile: fix few typos
    ... # disable pointer signed / unsigned warnings in gcc 4.0 ... # revert to pre-gcc-4.4 behaviour of .eh_frame ... -# information in a variable se we can use it in if_changed and friends. ...
    (Linux-Kernel)
  • Re: [Navy-patches] [PATCH] Makefile: fix few typos
    ... On Thursday 09 April 2009 03:34:34 pm Kirill Smelkov wrote: ... unsigned warnings in gcc 4.0 ... -# information in a variable se we can use it in if_changed and friends. ...
    (Linux-Kernel)
  • Re: undefined reference to `memset
    ... On Thu, 24 Mar 2005, Nick Barnes wrote: ... GCC should generate code which fills the array with zeroes. ... libgcc.a is probably part of gcc even in the freestanding case. ... The requirement for memsetand friends _is_ documented, ...
    (freebsd-stable)