Subject: Re: Is fclose(NULL) defined?
To: None <mike.long@analog.com>
From: Callum Gibson <callum@frost.bain.oz.au>
List: current-users
Date: 09/18/1995 11:54:06
Mike Long writes:
:-)callum@frost.bain.oz.au (Callum Gibson) writes:
:-)>If it's going to error-check stuff like that it should do it with asserts.
:-)>To silently allow bad code like fclose(NULL) is simply encouraging bad
:-)>programming.
:-)Have you looked at the code for fclose()?  The first thing it does is
:-)dereference its argument.  If the argument is NULL, then the result is
:-)a SEGV and a core dump.  That's not very silent. :-)

If it core dumps you're lucky. Unless I've been on a lot of naughty systems,
dereferencing null is not guaranteed to cause a segv. Maybe it is guaranteed
to on NetBSD/*.  In fact (start ghost-story) on a Pyramid 90-something running
OSx (dual universe O/S) dereferencing null gave you "^A", and I did come
across some code (author shall remain nameless to protect the guilty) that
did the following:

char *str;
...
if (strcmp(str, "^A") == 0)
etc.

to check for null pointers! Groan!(end ghost-story)

When I first started programming on Suns I noticed a lot more core dumps
than on the Pyramids - they were very forgiving. However, they let you get
away with a lot more bad code like deref-ing null pointers, with no indication
that you were doing anything wrong.

regards,
    Callum

Callum Gibson                                             callum@bain.oz.au
Fixed Income Division, DB Bain & Co.                          61 2 258 1620
## The opinions presented herein do not represent those of DB Bain & Co ###