Re: [PATCH] Use NULL instead of integer 0 in security/selinux/

From: Andrea Arcangeli
Date: Sat Jul 10 2004 - 02:12:43 EST


On Thu, Jul 08, 2004 at 10:32:32AM -0400, Richard B. Johnson wrote:
> On Thu, 8 Jul 2004, P. Benie wrote:
> > the integer 0 and null pointers are not the same, the compiler will
> > perform the appropriate conversion for you, so it is always correct to
> > define NULL as (void *)0.
>
> That's NOT what is says. It states that a NULL pointer is converted to
> the appropriate type before any comparison is made. It does NOT say
> that 0 is a valid null-pointer.

0 when casted or assigned to a pointer will be converted to the null
pointer value by the compiler, that's why doing !ptr is equivalent to
ptr == NULL, even if ptr points to address 0xffffffff virtual in
reality. Still NULL is set to (void *) 0, or alternatively (void *) -1UL
(thought the latter I'm not 100% sure but I think it'll work in such a
case).

It's mostly theory though, I've never seen an arch with a compiler with
a null pointer not actually meaning virtual address 0UL (that's why we
used a C-breaking #define NULL ((void*)-1UL) once we needed it).
-
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/