From: Alan Stern <stern@rowland.harvard.edu>
To: Horst von Brand <vonbrand@inf.utfsm.cl>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Style question: Should one check for NULL pointers?
Date: Fri, 11 Jul 2003 17:21:33 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.44L0.0307111714130.10595-100000@netrider.rowland.org> (raw)
In-Reply-To: <200307111932.h6BJWMr5004606@eeyore.valparaiso.cl>
On Fri, 11 Jul 2003, Horst von Brand wrote:
> My personal paranoia when reading code goes the other way: How can I be
> sure it won´t ever be NULL? Maybe it can't be now (and to find that out an
> hour grepping around goes by), but the very next patch introduces the
> possibility. Better have the function do an extra check, or make sure
> somehow the assumption won't _ever_ be violated. But that is a large (huge,
> even) cost, so...
Suppose something does change and your function is passed a NULL pointer
after all. What will you do about it then? Clearly this represents a
mistake on the part of the caller; are you simply going to return without
doing anything and hope that nothing else will go wrong? Or will you
return an error code and hope that a caller careless enough to pass an
invalid argument will also be careful enough to check the return code?
Quite a lot of places in the kernel do one of these (usually the first).
Neither of those options is attractive to me. I would prefer something
that leaves a clear indication that the problem exists. A logged error
message would help; a BUG_ON or segfault would be even better. This is
especially true in situations where the function in question is part of a
relatively small subsystem where you _know_ that a NULL pointer is never
valid. (It may occur, but if it does it must represent an error.)
Alan Stern
next prev parent reply other threads:[~2003-07-11 21:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-10 20:28 Style question: Should one check for NULL pointers? Alan Stern
2003-07-10 20:52 ` Eli Carter
2003-07-10 22:12 ` H. Peter Anvin
2003-07-11 2:35 ` Alan Stern
2003-07-11 14:29 ` Eli Carter
2003-07-11 15:16 ` Alan Stern
2003-07-12 18:40 ` Horst von Brand
2003-07-13 21:42 ` Alan Stern
2003-07-11 20:33 ` H. Peter Anvin
2003-07-10 22:54 ` David D. Hagood
2003-07-11 4:02 ` Hollis Blanchard
2003-07-11 4:38 ` Hua Zhong
2003-07-11 14:13 ` David D. Hagood
2003-07-11 14:52 ` Richard B. Johnson
2003-07-11 15:39 ` Alan Stern
2003-07-11 19:32 ` Horst von Brand
2003-07-11 20:36 ` H. Peter Anvin
2003-07-11 21:21 ` Alan Stern [this message]
2003-07-13 22:53 ` Ingo Oeser
[not found] <7QmZ.5RP.17@gated-at.bofh.it>
2003-07-10 21:00 ` Dennis Bliefernicht
2003-07-10 22:13 ` H. Peter Anvin
2003-07-10 22:28 ` Larry McVoy
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=Pine.LNX.4.44L0.0307111714130.10595-100000@netrider.rowland.org \
--to=stern@rowland.harvard.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=vonbrand@inf.utfsm.cl \
/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.