All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Hua Zhong" <hzhong@cisco.com>
To: "'David D. Hagood'" <wowbagger@sktc.net>,
	"'Alan Stern'" <stern@rowland.harvard.edu>
Cc: <linux-kernel@vger.kernel.org>
Subject: RE: Style question: Should one check for NULL pointers?
Date: Thu, 10 Jul 2003 21:38:29 -0700	[thread overview]
Message-ID: <01c701c34766$4706cc50$743147ab@amer.cisco.com> (raw)
In-Reply-To: <3F0DEEA4.5050605@sktc.net>

> There is an old saying in software design:
> 
> "Never check for an error condition that you do not know how 
> to handle."
> 
> In other words: if you have identified a possible error 
> condition (such as a NULL pointer), until you have identified a way to
meaningfully 
> handle that error condition, simply testing for it is useless.
> Now, if you have some function that can return an error code, then 
> testing for NULL and returning an error condition is sensible. But if 
> you have no way to report the error, then what good is the test?

Not always true. In some cases you know how to handle: just return
without doing anyting.

man 3 free

It's an example that passing a NULL is allowed by the API.
 
> However, if you test for NULL, and log a report when you 
> detect it then 
> deref it anyway (to force an OOPS, in other words throw an 
> exception), 
> then at least there is some meaningful info in the log.
> 
> But just doing something like
> 
> void foo(void *ptr)
> {
>     if (!ptr)
>       return;
> 
>     ....
> }
> 
> just masks the problem.
> 
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


  parent reply	other threads:[~2003-07-11  4:23 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 [this message]
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
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='01c701c34766$4706cc50$743147ab@amer.cisco.com' \
    --to=hzhong@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=wowbagger@sktc.net \
    /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.