Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!sumax!amc-gw!john From: john@amc-gw.UUCP (John Sambrook) Newsgroups: comp.unix.wizards Subject: Re: Referencing NULL pointers Message-ID: <504@amc-gw.UUCP> Date: 11 Jul 89 01:43:11 GMT References: <19367@paris.ics.uci.edu> Reply-To: john@amc-gw.UUCP (John Sambrook) Followup-To: comp.lang.c Organization: Applied Microsystems Corporation, Redmond, WA. Lines: 36 As several people have commented dereferencing NULL pointers is not an acceptable practice, even though you can get away with it on several architectures. There is another somewhat related issue, and that is that you have to be careful to make sure that the type of pointer you are dereferencing is correct for the given usage. For example, I have seen the following code from time to time: { int fd; struct stat s; ... if (read(fd, &s, sizeof(struct stat)) != sizeof(struct stat)) ... } The problem with this code is that the second argument in the read() call is of the wrong type; it should be of type "char *", yet in fact it is of type "struct stat *". I spent several years working on a machine (Data General MV series) where this type of code would result in a segmentation violation when it was executed. Needless to say, I fixed a lot of bugs like this. Fortunately the MV had a very good compiler, which made finding bugs like this relatively easy. -- John Sambrook DNS: john@amc.com Applied Microsystems Corporation UUCP: amc-gw!john Redmond, Washington 98073 Dial: (206) 882-2000 ext. 630