From: Eyal Lebedinsky <eyal@eyal.emu.id.au>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Use NULL instead of integer 0 in security/selinux/
Date: Sat, 10 Jul 2004 19:31:33 +1000 [thread overview]
Message-ID: <40EFB775.8020408@eyal.emu.id.au> (raw)
In-Reply-To: <m1fz80c406.fsf@ebiederm.dsl.xmission.com>
Executive summary:
It is not about the law (ANSI). It is about best practices
that improve code quality. And transparency in the
programmer's expression should always be welcome.
This thread can easily degrade into a religious argument
(an oxymoron, can't argue about religion so just don't do
it). I hope the below addresses the issues raised here
and gives reason for my opinions.
Eric W. Biederman wrote:
> Does this mean constructs like:
> ``if (pointer)'' and ``if (!pointer)'' are also outlawed.
Very much yes. I will go further and say that only boolean
variables should use the above syntax. Using
if (i)
where 'i' is a non-boolean integer instead of
if (0 != i)
makes me question what the programmer wanted. Since integers
do not have clear names for true/false logic (booleans usually
will be called something like 'have_brain" etc.) the simple
'if (i)' may just as well be a miswritten 'if (!i)' - and I
caught a few of these bugs in my time.
The whole point is not about "does the blind law of ANSI accepts
this" because ANSI is written to be as permissible as possible
so as not to invalidate deprecated bad style.
The whole point is about writing code that has a clear meaning, and
using different forms for a zero integer and a generic empty pointer
is a good way to force the writer to think and do the right thing.
Fact is that some code I can read as I see the snippet and without
having to resort to too much header checking etc, while other code
is a pain to go through (and don't even start me on consistent
indentation).
And just to be clear. ANSI says this is valid
char *p;
int i;
...
i[p] = 1;
Do you encourage this too? See what I mean? OK, so we all read
the reference to the obfuscation competition...
> And do we then need to initialize static pointers to NULL instead
> of letting them be implicitly 0.
I surely insist on this. Implicit is just not good enough to show
that you gave it enough thought.
> Is doing memset(&(struct with_embeded_pointers), 0, sizeof(struct))
> also wrong?
You probably think that 'calloc' is enough for initializing an
object. I fixed enough problems from this. You declare a struct
- write a struct_clear function right away. It is worth it's
wordcount in gold.
> I don't see that 0 is WRONG. I do agree that ``((void *)0)'' is
> slightly more typesafe than ``0'', but since we don't have a lot of
> (void *) pointers in the kernel that is still the WRONG pointer type.
>
> I do see that NULL has superior readability and maintainability and so
> should be encouraged by Documentation/CodingStyle.
>
> The B and K&R roots of a simple single type language are what give C
> most of it's simplicity flexibility and power. Please don't be so
> eager to throw those out.
Yes, it was simple and flexible. It was a damn great improvement
over assembly. However, by now it is clear that stronger typing
is a good thing. Kernel code, where bugs have a high cost, is a good
place to apply stricter rules than usual.
> You want to be so typesafe it sounds like you want to recode the
> kernel in Pascal. You've written sparse, so it should be just a little
> more work to write a Pascal backend. After that the kernel will be so
> typesafe the compiler won't let us poor programmers get it wrong.
Did we forget the smiley?
--
Eyal Lebedinsky (eyal@eyal.emu.id.au)
next prev parent reply other threads:[~2004-07-10 9:32 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-07 19:25 [PATCH] Use NULL instead of integer 0 in security/selinux/ Chris Wright
2004-07-08 3:12 ` Herbert Xu
2004-07-08 3:27 ` David S. Miller
2004-07-08 3:43 ` Miles Bader
2004-07-08 5:22 ` Linus Torvalds
2004-07-08 5:35 ` Miles Bader
2004-07-08 15:58 ` Linus Torvalds
2004-07-08 16:23 ` Dave Jones
2004-07-08 17:57 ` Geert Uytterhoeven
2004-07-09 11:23 ` Roman Zippel
2004-07-10 19:41 ` Geert Uytterhoeven
2004-07-11 10:29 ` Geert Uytterhoeven
2004-07-11 10:54 ` viro
2004-07-11 16:14 ` Linus Torvalds
2004-07-11 20:05 ` H. Peter Anvin
2004-07-12 15:58 ` Florian Weimer
2004-07-12 16:34 ` H. Peter Anvin
2004-07-08 11:18 ` Herbert Xu
2004-07-08 13:10 ` Andreas Schwab
2004-07-08 13:56 ` Herbert Xu
2004-07-08 14:13 ` Andreas Schwab
2004-07-08 5:19 ` Linus Torvalds
2004-07-08 16:09 ` Timothy Miller
2004-07-08 16:21 ` Linus Torvalds
2004-07-08 16:27 ` Linus Torvalds
2004-07-08 16:52 ` Timothy Miller
[not found] ` <200407090056.51084.vda@port.imtp.ilyichevsk.odessa.ua>
2004-07-12 15:17 ` Timothy Miller
2004-07-12 16:12 ` Andreas Schwab
2004-07-12 16:51 ` Andrew Pimlott
2004-07-15 16:15 ` Timothy Miller
2004-07-09 20:36 ` Eric W. Biederman
2004-07-09 23:49 ` Paul Jackson
2004-07-10 1:43 ` Kyle Moffett
2004-07-10 1:47 ` Herbert Xu
2004-07-10 21:53 ` Alexandre Oliva
2004-07-10 6:18 ` Linus Torvalds
2004-07-10 6:23 ` Linus Torvalds
2004-07-10 6:58 ` Andrea Arcangeli
2004-07-10 9:48 ` Eric W. Biederman
2004-07-10 15:39 ` Roland Dreier
2004-07-11 2:45 ` Eyal Lebedinsky
2004-07-11 21:19 ` Olaf Titz
2004-07-10 9:39 ` Eric W. Biederman
2004-07-10 9:56 ` Herbert Xu
2004-07-11 21:47 ` Olaf Titz
2004-07-13 8:43 ` Geert Uytterhoeven
2004-07-14 3:12 ` Alexandre Oliva
2004-07-13 18:53 ` Elladan
2004-07-14 3:15 ` Alexandre Oliva
2004-07-10 12:11 ` Roman Zippel
2004-07-10 21:59 ` Alexandre Oliva
2004-07-11 4:40 ` Linus Torvalds
2004-07-10 9:31 ` Eyal Lebedinsky [this message]
2004-07-10 22:07 ` Alexandre Oliva
2004-07-10 23:52 ` Paul Jackson
2004-07-11 0:12 ` Tim Wright
2004-07-12 22:03 ` Bill Davidsen
2004-07-10 8:18 ` Florian Weimer
2004-07-08 11:10 ` Richard B. Johnson
2004-07-08 11:28 ` Michael Buesch
2004-07-08 11:44 ` Martin Zwickel
2004-07-08 12:06 ` Michael Buesch
2004-07-08 12:38 ` [OT] NULL versus 0 (Re: [PATCH] Use NULL instead of integer 0 in security/selinux/) Kari Hurtta
2004-07-08 12:42 ` Michael Buesch
2004-07-08 12:57 ` Kari Hurtta
2004-07-08 15:25 ` Herbert Xu
2004-07-10 8:22 ` [PATCH] Use NULL instead of integer 0 in security/selinux/ Florian Weimer
2004-07-08 11:43 ` P. Benie
2004-07-08 14:32 ` Richard B. Johnson
2004-07-08 15:00 ` Michael Poole
2004-07-08 15:30 ` P. Benie
2004-07-08 15:55 ` Andreas Schwab
2004-07-10 7:09 ` Andrea Arcangeli
2004-07-10 7:02 ` Andrea Arcangeli
2004-07-10 6:59 ` Andrea Arcangeli
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=40EFB775.8020408@eyal.emu.id.au \
--to=eyal@eyal.emu.id.au \
--cc=linux-kernel@vger.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.