Invalid Pointers (was Re: Referencing NULL pointers)

Steven M. Bellovin smb at ulysses.homer.nj.att.com
Mon Jul 17 12:24:55 AEST 1989


In article <4348 at eos.UUCP>, jbm at eos.UUCP (Jeffrey Mulligan) writes:
> It has been pointed out that there should be no assumptions
> about what addresses are valid; is there any way to get
> a guaranteed INVALID address?
> 
> I commonly do this sort of thing:
> 
> struct foobar { /* some stuff */};
> 
> static struct foobar *fb1=NO_FOOBAR;
....
> So, the question is, how should NO_FOOBAR be defined?

>From the C Reference Manual, section 7.7, ``Equality Operators'':

	A pointer may be compared to an integer only if the integer is
	the constant 0.  A pointer to which 0 has been assigned is
	guaranteed not to point to any object and will appear to be
	equal to 0.  In conventional usage, such a pointer is
	considered to be null.

In other words, NO_FOOBAR should be defined as 0.  And this is a strong
hint to those who think that dereferencing 0 is legal.


		--Steve Bellovin



More information about the Comp.unix.wizards mailing list