Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Null Pointer exceptions |
| Date | 2015-04-22 18:02 -0400 |
| Organization | Self |
| Message-ID | <55381A74.3000107@verizon.net> (permalink) |
| References | <mh9451$ib4$1@speranza.aioe.org> |
On 04/22/2015 05:34 PM, jeff wrote:
> Howdy
>
> I've got a large C codebase that frequently triggers bugs where pointers
> that shouldn't be null, somehow end up getting nulled.
>
> It's easy enough to fix up each individual bug when it gets reported,
> just by adding a null check:
>
> if
> ((void*) ptr != (void*)NULL)
> {
> // existing code that triggered a crash
> }
>
> However, as these null conditions only show up occasionally, there always
> seem to be more bugs left to find.
>
> My question is: is there a way to deal with all of these problems in one
> swoop, by ignoring all code that dereferences a null pointer, i.e. null
> dereference becomes a NO-OP instead of triggering an exception. ?
Every time a pointer that shouldn't be null gets dereferenced, you
should investigate to find out why it was null. Don't simply patch over
the problem by checking whether it is null - find out why it was
unexpectedly null. Fix that problem. Then look for other similar
problems - if this problem comes up repeatedly, you've probably made the
same kind of mistake (whatever that mistake might be) in many different
location.
You'll never get anywhere with debugging your code if you concentrate
your efforts on covering up symptoms, rather than tracking down causes.
You're like a doctor who sees a patient coughing up blood, and
concentrates his attention on cleaning up the blood. A proper doctor
need to figure out why the patient is bleeding internally before the
doctor can put a stop to it, otherwise the bleeding will just continue
until the patient dies as a result.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Null Pointer exceptions jeff <nospam@nospam.com> - 2015-04-22 21:34 +0000
Re: Null Pointer exceptions James Kuyper <jameskuyper@verizon.net> - 2015-04-22 18:02 -0400
Re: Null Pointer exceptions Stephen Sprunk <stephen@sprunk.org> - 2015-04-22 18:30 -0500
Re: Null Pointer exceptions James Kuyper <jameskuyper@verizon.net> - 2015-04-22 19:44 -0400
Re: Null Pointer exceptions Stephen Sprunk <stephen@sprunk.org> - 2015-04-23 11:53 -0500
Re: Null Pointer exceptions Richard Heathfield <rjh@cpax.org.uk> - 2015-04-23 18:59 +0100
Re: Null Pointer exceptions Barry Schwarz <schwarzb@dqel.com> - 2015-04-22 15:17 -0700
Re: Null Pointer exceptions James Dow Allen <gmail@jamesdowallen.nospam> - 2015-04-23 04:11 +0000
Re: Null Pointer exceptions Robert Wessel <robertwessel2@yahoo.com> - 2015-04-22 17:19 -0500
Re: Null Pointer exceptions Ben Bacarisse <ben.lists@bsb.me.uk> - 2015-04-22 23:46 +0100
Re: Null Pointer exceptions Nobody <nobody@nowhere.invalid> - 2015-04-23 03:14 +0100
Re: Null Pointer exceptions James Kuyper <jameskuyper@verizon.net> - 2015-04-23 12:32 -0400
csiph-web