What machines core dump on deref of NULL?

Conor P. Cahill cpcahil at virtech.uucp
Sat Jun 30 09:26:56 AEST 1990


In article <412 at minya.UUCP> jc at minya.UUCP (John Chambers) writes:
>Hey, wait just a minute here.  I can't let such an erroneous error go
>unchallenged!  Dereferencing a null pointer is quite definitely *not*
>an error, bug, mistake, or any other pejorative, in a great many sorts
>of applications.
>
>The trouble with generalizing to all C code is that C outgrew Unix
>about a decade ago.

HOWEVER, this is not comp.lang.c.  This comp.unix.whatever and in this
context dereferencing a null pointer is, or should be, a no-no.  Any 
unix code that does, has at least 1 serious bug that should be fixed.

I remember one time when I was porting some code to a sun 3 and 
ran across the following line of code:

	if( strcmp(variable,(char*)0) == 0 )

I really wasn't sure what the original programmer was attempting to 
check (since the first byte at 0 was a null byte on the original machine),
so I changed the code to be:

	if( (variable == (char *)0) || (*variable == '\0'))


-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.wizards mailing list