On Tue, 28 Nov 2006 23:17:13 +0100, Jesper Juhl said: > 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". For those playing along at home - often the bug (not here though) is it should have been a *signed* long, because arg2 could be passed from some other function that returns negative numbers on error? Remember that papering over a bug is a bad idea... On Tue, 28 Nov 2006 14:27:51 PST, Linus Torvalds said: > 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 Unfortunately, it's *easy* for GCC to determine that Something Odd has happened. Either the variable was made unsigned in error, or the test is in error. However, there's no real way for the compiler to know which was intended. And let's face it - we've had enough of our share of bugs *both* ways, which is why GCC emits a warning.
Attachment:
pgpHzLI3yztJ9.pgp
Description: PGP signature
- References:
- [PATCH] Don't compare unsigned variable for <0 in sys_prctl()
- From: Jesper Juhl <[email protected]>
- [PATCH] Don't compare unsigned variable for <0 in sys_prctl()
- Prev by Date: [PATCH] for 2.6.20 infiniband/ib_cm: fix path migration support
- Next by Date: Re: [PATCH] Don't compare unsigned variable for <0 in sys_prctl()
- Previous by thread: Re: [PATCH] Don't compare unsigned variable for <0 in sys_prctl()
- Next by thread: Regression: spurious 8259A interrupt: IRQ7 appears in 2.6.19-rc6-git10
- Index(es):