Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!ucbvax!ulysses!smb From: smb@ulysses.homer.nj.att.com (Steven M. Bellovin) Newsgroups: comp.unix.wizards Subject: Re: Invalid Pointers (was Re: Referencing NULL pointers) Message-ID: <11892@ulysses.homer.nj.att.com> Date: 17 Jul 89 02:24:55 GMT References: <20245@adm.BRL.MIL> <4348@eos.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 26 In article <4348@eos.UUCP>, jbm@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