Subject: Re: segmentation fault on fclose?
To: None <current-users@netbsd.org>
From: Christos Zoulas <christos@deshaw.com>
List: current-users
Date: 09/12/1994 16:36:35
In article <199409061410.KAA02228@Collatz.McRCIM.McGill.EDU> mouse@Collatz.McRCIM.McGill.EDU (der Mouse) writes:
>and having to fire up a debugger to discover where it died.  Something
>like this, perhaps:
>
>	fclose(FILE *fp)
>	{
>	 if (! fp)
>	  { write(2,"fclose(NULL) called\r\n",21);
>	    kill(getpid(),SIGABRT);
>	  }
>	 ....
>	}

I assume that after this, we should all fix our c libraries to
be more friendly such as:

int
strcmp(const char* src1, const char* src2)
{
#define MSG(a) write(2, a, sizeof(a) - 1)
	if (src1 == NULL) {
		MSG("You called strcmp with a null first argument.\r\n\
You should not be doing that, or your program will die.\r\n\
This message is intended to help you debug your program.\r\n");
		kill(0, SIGABRT);
	}

	if (src2 == NULL) { 
		MSG("You called strcmp with a null second argument.\r\n\
You should not be doing that, or your program will die.\r\n\
This message is intended to help you debug your program.\r\n");
	    kill(0, SIGABRT);
	}

	....
}


NOT!

The unix library is written with out any argument checking in most places;
it is intended to be fast and small, and not to protect a programmer from
her/his own bugs.

christos