What is wrong with this program?

Guy Harris guy at sun.uucp
Wed Aug 21 03:49:19 AEST 1985


> You have a pointer, but it doesn't point to anything.  On
> a Convex C-1, this leads to a core dump when "fread" tries to do a "bcopy"
> with a null pointer.... which is invalid as a user address.  On VAXen and
> other machines, null pointers are valid user addresses, which can make
> finding such problems a lot more difficult.

On several other machines, null pointers are not valid user addresses; Suns
and CCI Power 5/20s come to mind (not surprisingly).  On VAXes running VMS,
null pointers are not valid user addresses; on VAXes running System V
Release 2 Version 2, or 4.2BSD with John Bruner's changes, there's a loader
option to build executable images where null pointers aren't valid.  Use
these options - they can catch problems before you have to move your code to
a machine where you have no alternative (besides, the chances are
non-negligible that your code has a problem even if you can dereference a
null pointer).

> Hint:  Learn about the program "lint" and use it regularly.  It might have
> saved you a lot of work.

Amen.  MANY program bugs (even ones in the kernel - I can testify to this)
can be caught simply by using "lint".  There may be some things that "you
just can't get lint to shut up about", but better too many complaints than
too few...

	Guy Harris



More information about the Comp.lang.c mailing list