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

From: Roland Dreier
Date: Sat Jul 10 2004 - 10:45:59 EST


Linus> I really don't see the point of complaining about the
Linus> fixes. There's just _no_ way to say that "0" is more
Linus> readable than "NULL" in any of the cases. I dare you -
Linus> show _one_ case where a 0/NULL patch was wrong or even
Linus> remotely debatable. I dare you.

I don't know if any of the 0/NULL kernel patches were of this form,
but I've seen sparse complain about this in my code and found it
somewhat annoying. I think the following is at least remotely debatable...

Suppose I have

struct foo {
int a;
int b;
};

then sparse is perfectly happy with someone clearing out a struct foo
like this:

struct foo bar = { 0 };

but then if someone changes struct foo to be

struct foo {
void *x;
int a;
int b;
};

sparse will complain about that initialization, and all of the fixes
I can think of seem somewhat worse than the original to me:

struct foo bar = { NULL }; /* will I have to change this
again if struct foo changes? */

or

struct foo bar = { .a = 0 }; /* why do I have to name a member? */

or

struct foo bar;
memset(&bar, 0, sizeof bar); /* WRONG if a null pointer is not
the bit pattern 0 */

- Roland
-
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/