B
Ben Bacarisse
Keith Thompson said:Oops, what I *meant* was
buf = realloc(buf, 200);
The point I was making upthread was specifically about realloc() (and of
course I messed that up by typoing "malloc" in place of "realloc").
Assigning the result of realloc() to the pointer object given as the
first argument is considered a bad idea because, if the realloc() call
fails and returns a null pointer, you've lost your only pointer to the
original buffer. My point was merely that losing that pointer is bad
only if you would have made use of it. If your response to an realloc()
failure is going to be to abort the program anyway, then you might as
well write
buf = realloc(buf, new_size);
I did *not* mean to suggest omitting the check for a null pointer. If
an allocation call fails, you want to deal with it immediately -- even
if you're just going to abort the program.
Yes, I got that that was your point, and I had nothing to say about it
(because I agree). That's why I replied to Jens's post and not yours.