All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jesper Juhl" <jesper.juhl@gmail.com>
To: "Linus Torvalds" <torvalds@osdl.org>
Cc: linux-kernel@vger.kernel.org, "Andrew Morton" <akpm@osdl.org>,
	trivial@kernel.org
Subject: Re: [PATCH] Don't compare unsigned variable for <0 in sys_prctl()
Date: Tue, 28 Nov 2006 23:34:27 +0100	[thread overview]
Message-ID: <9a8748490611281434g3741045v5e7f952f633e08d3@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0611281425220.4244@woody.osdl.org>

On 28/11/06, Linus Torvalds <torvalds@osdl.org> wrote:
>
>
> 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".
>
Hehe, ok, I'll stop cleaning this stuff up then.
Nice little hobby out the window there ;)

-- 
Jesper Juhl <jesper.juhl@gmail.com>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html

  reply	other threads:[~2006-11-28 22:34 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 [this message]
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 ` Friends dont let friends use GCC -W (was Re: [PATCH] Don't compare unsigned Valdis.Kletnieks

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=9a8748490611281434g3741045v5e7f952f633e08d3@mail.gmail.com \
    --to=jesper.juhl@gmail.com \
    --cc=akpm@osdl.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.