mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu
To: Jesper Juhl <jesper.juhl@gmail.com>
Cc: linux-kernel@vger.kernel.org, Linus Torvalds <torvalds@osdl.org>,
	Andrew Morton <akpm@osdl.org>,
	trivial@kernel.org
Subject: Friends dont let friends use GCC -W (was Re: [PATCH] Don't compare unsigned
Date: Tue, 28 Nov 2006 17:58:32 -0500	[thread overview]
Message-ID: <200611282258.kASMwW2f025365@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Tue, 28 Nov 2006 23:17:13 +0100." <200611282317.14020.jesper.juhl@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1171 bytes --]

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 #2: Type: application/pgp-signature, Size: 226 bytes --]

      parent reply	other threads:[~2006-11-28 22:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-28 22:17 [PATCH] Don't compare unsigned variable for <0 in sys_prctl() Jesper Juhl
2006-11-28 22:27 ` Linus Torvalds
2006-11-28 22:34   ` Jesper Juhl
2006-11-28 23:06     ` Linus Torvalds
2006-11-28 23:42       ` Jesper Juhl
2006-11-29  0:13         ` Linus Torvalds
2006-11-29  1:10           ` Jesper Juhl
2006-11-28 22:58 ` Valdis.Kletnieks [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200611282258.kASMwW2f025365@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=akpm@osdl.org \
    --cc=jesper.juhl@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=trivial@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®