Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c
From: Linus Torvalds (torvalds_at_osdl.org)
Date: 11/23/04
- Previous message: Pete Zaitcev: "ub: oops with preempt ("Sahara Workshop")"
- In reply to: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Next in thread: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Reply: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Reply: Timur Tabi: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 23 Nov 2004 10:03:55 -0800 (PST) To: Jesper Juhl <juhl-lkml@dif.dk>
On Tue, 23 Nov 2004, Jesper Juhl wrote:
>
> Linus, would you accept patches like this?
No, please don't.
The warning is sometimes useful, but when it comes to a construct like
if (a < 0 || a > X)
the fact that "a" is unsigned does not make the construct silly. First
off, it's (a) very readable and (b) the type of "a" may not be immediately
obvious if it's a user typedef, for example.
In fact, the type of "a" might depend on the architecture, or even
compiler flags. Think about "char" - which may or may not be signed
depending on ABI and things like -funsigned-char.
In other places, it's not "unsigned" that is the problem, but the fact
that the range of a type is smaller on one architecture than another. So
you might have
inf fn(pid_t a)
{
if (a > 0xffff)
...
}
which might warn on an architecture where "pid_t" is just sixteen bits
wide. Does that make the code wrong? Hell no.
IOW, a lot of the gcc warnings are just not valid, and trying to shut gcc
up about them can break (and _has_ broken) code that was correct before.
> I probably won't be able to properly evaluate/review *all* the instances
> of this in the kernel,
It's not even that I will drop the patches, it's literally that "fixing"
the code so that gcc doesn't complain can be a BUG. We've gone through
that.
Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- Previous message: Pete Zaitcev: "ub: oops with preempt ("Sahara Workshop")"
- In reply to: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Next in thread: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Reply: Jesper Juhl: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Reply: Timur Tabi: "Re: [PATCH] Remove pointless <0 comparison for unsigned variable in fs/fcntl.c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|