An Ubiquitous C bug

house ron s64421 at zeus.usq.EDU.AU
Tue Jan 22 02:22:12 AEST 1991


Here's a bug which exists in every single DOS C compiler I can find,
and may also exist on others:

In the small memory model, it is possible for a function to have the
address NULL.  E.G.:

void x()
{
...
}

main()
{
   void (*y)();
   y = x;
   if (y==NULL) printf ("AARRGGHH!!\n");
}

This sort of program CAN print the message if x() happens to be
loaded by the linker at the start of the code segment (address 0).
The compiler seems unable to prevent the linker from loading
functions at that address.  Perhaps on some machines, NULL should
_not_ be 0?  After all, it would be easy to prevent functions being
loaded at address 1 (for example) on a DOS machine.

--
Regards,

Ron House.   (s64421 at zeus.usq.edu.au)
(By post: Info Tech, U.C.S.Q. Toowoomba. Australia. 4350)



More information about the Comp.lang.c mailing list