references to dereferenced null pointers

David Smallberg das at lanai.cs.ucla.edu
Sat Mar 17 11:47:08 AEST 1990


In article <1990Mar14.164539.23685 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>There is absolutely nothing wrong with having a pointer representation in
>which the bit pattern for a null pointer is not all zeros... except that
>there are a lot of old, badly-written programs which will break.  Thus my
>earlier comment that it is valid but unwise.

I've seen "the constant 0" misinterpreted in this way:

	thing *array[100];

		/* clear array to NULLs */   <-- WRONG
	(void) memset(array,0,sizeof(array));
		or
	(void) memset(array,NULL,sizeof(array));

The offender believes that since he's using the constant 0, the compiler
will use the appropriate bit pattern for a NULL pointer, even if that's not
all-zero-bits.

-- David Smallberg, das at cs.ucla.edu, ...!{uunet,ucbvax,rutgers}!cs.ucla.edu!das



More information about the Comp.lang.c mailing list