[vox-tech] malloc() is ... old school?

Micah J. Cowan vox-tech@lists.lugod.org
Fri, 21 Mar 2003 13:14:06 -0800


On Fri, Mar 21, 2003 at 01:01:39PM -0800, Jeff Newmiller wrote:

> > >
> > > And I submit that without the core dump, the bug of having forgotten
> > > to set *person's fields just got much, much harder to track down.
> > >
> > 
> > Core dumps are useful for tracking down bugs.
> 
> While I am not very comfortable with bunches of NULL pointers in records, 
> I am not sure that depending on the garbage in a malloc'd memory block to
> be non-NULL is a good idea either.

No, it's not. But it is at least a good deal more likely to be
non-NULL.

But you're right: a more reliable way to ensure core dumps when you
make an error of this sort is to *specifically* initialize all values
to something you *know* will dump core. I've heard from people that do
this.

Of course, this really doesn't get you anywhere, since you could
forget to initialize your pointers to garbage just as easily as you
can forget to initialize them to something more meaningful. And
linking with electric fence will get you about the same level of
reliability, with much less work.

Turning on -W -Wall -O2 and not ignoring the resulting warnings can be
very helpful for detecting initialization problems, too. But I still
prefer the direct, blunt forcefulness that a core dump presents... :-)

-Micah