Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!rutgers!att!mtunb!dmt From: dmt@mtunb.ATT.COM (Dave Tutelman) Newsgroups: comp.sys.ibm.pc Subject: Re: How Turbo C Handles Null Pointer Assignments Summary: ... and a tool to help debug such problems. Message-ID: <1497@mtunb.ATT.COM> Date: 11 May 89 11:25:06 GMT References: <4178@sybase.sybase.com> <1778@wasatch.utah.edu> Reply-To: dmt@mtunb.UUCP (Dave Tutelman) Organization: AT&T Bell Labs - Middletown, NJ Lines: 119 In article <1778@wasatch.utah.edu> jacobs%cmos.utah.edu@wasatch.utah.edu (Steven R. Jacobs) writes: >In article <4178@sybase.sybase.com> forrest@sybase.com writes: >>... [ Turbo C checks ] ... >>the memory area starting with address 0 and continuing through >>where the message is stored that you see when you run Turbo C. > >This "checksum" is actually the Turbo C copyright string. If it >gets tromped on, the "Null Pointer Assignment" message is given. Both Microsoft C and Turbo C detect Null Pointer Assignments this way. (Maybe others do as well.) The code below is a debugging tool I have occasionally used to track down null pointer assignments in C programs. It is based on the same principle. It has worked in Microsoft C 4.x and 5.0, and Turbo C 1.0 and 2.0. It remains independent of which compiler/version you use because it initializes its reference string at run time (based on the initial contents of the null-pointer area). Enjoy! +---------------------------------------------------------------+ | Dave Tutelman | | Physical - AT&T Bell Labs - Middletown, NJ | | Logical - ...att!mtunb!dmt | | Audible - (201) 957 6583 | +---------------------------------------------------------------+ /************************************************************* * * NULLPTR - Dave Tutelman - March 1988 * * Test for a null pointer violation. * Complain and quit if found. * * nullptr (string) * char *string; * * FIRST CALL - string should be empty (""), to initialize. * SUBSEQUENT CALLS - if a null pointer violation is found, * the program displays (1) the string, and (2) the * null pointer area violations, then quits. * * As distributed, this file contains a sample main program to * (1) demonstrate the use of nullptr(), and * (2) test its effectiveness in your environment. * To use nullpr() in your own program, recompile after commenting out * the "#define SAMPLE" line. */ #define SAMPLE #include #define NULLVECSIZE 80 static char nullvector[NULLVECSIZE]; nullptr (s) char *s; { int i; char *p; if (!strlen (s)) { /* initialize nullvector */ for (i=0, p=NULL; i