Re: [PATCH] Use NULL instead of integer 0 in security/selinux/
From: Linus Torvalds
Date: Thu Jul 08 2004 - 00:23:20 EST
On Thu, 8 Jul 2004, Herbert Xu wrote:
>
> Chris Wright <chrisw@xxxxxxxx> wrote:
> > Fixup another round of sparse warnings of the type:
> > warning: Using plain integer as NULL pointer
>
> What's wrong with using 0 as the NULL pointer? In contexts where
> a plain 0 is unsafe, NULL is usually unsafe as well.
It's not about "unsafe". It's about being WRONG.
The fact is, people who write "0" are either living in the stone age, or
are not sure about the type. "0" is an _integer_. It's not a pointer. It
may be legal C, but that doesn't make it right anyway. "0" also happens to
be one of the more _common_ integers, so mistakes happen.
Looking at the code, people that used "0" for NULL pointers quite often
obviously were NOT aware of the types. The code just happened to pass
through the compiler without warnings.
The same is true the other way too. I've seen too many damn people who use
NULL in an integer context, and any compiler system that makes NULL be
just a plain "0" is frigging _broken_. NULL is _not_ an integer. Never
has been, and if the compiler doesn't warn loudly about obviously idiotic
code, then the compiler is broken.
In other words:
char * p = 0; /* IS WRONG! DAMMIT! */
int i = NULL; /* THIS IS WRONG TOO! */
and anybody who writes code like the above either needs to get out of the
kernel, or needs to get transported to the 21st century.
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/