Dereferencing NULL
Peter Lamb
prl at mulga.SUN
Mon Nov 28 14:02:55 AEST 1983
Dereferencing NULL pointers is yet another example of idiots who
write 'portable' code, assuming however, that **THEIR** machine is the
only one on which it will ever run: the same sorts of people who designed
cpio with binary headers.
Even on a VAX, dereferencing NULL will get you garbage: sure, *(char *)NULL
and *(short *)NULL return you 0, but *(int *)NULL will give you
1024528128 !!!!.
On other machines, *NULL has all sorts of diverting contents:
On our PE3200, fputs(stdout, NULL) yeilds "'xX\007", the HP9000 will
trap it (the best thing to do if possible), the results on stand-alone
68000 programs (like the kernel) have already been well canvassed.
I would suggest that the register save mask for VAX START procedures was
made 0xffff, but for sure, some cretin would make his/her program depend
on the 'fact' that *(char *)NULL was -1. (For the DEC-bound, there is NO
guarantee that 'char's are signed!!)
As a non-DEC UNIX site for the past 5 years, we have been battling
against programmers who assume all sorts of magical properties about
computers: that characters are signed, that there is some standard
order of bytes in a word, that 'int's are preordained to be 16 bits (that
shows age, now they all have 32 bits!!) and now, the latest craze is to
dereference NULL.
Like division by zero, dereferencing NULL is a ** B U G **
and SHOULD cause programs to blow up, preferably by causing an address
trap IMMEDIATELY.
Peter Lamb, Melbourne Uni decvax!mulga!prl
More information about the Comp.unix.wizards
mailing list