In this section:
This error is generated whenever an expression operates on the Expression uses
Code Description Enabled Reported Platform EXPR_NULL
In the following code, the pointer
a is initialized to zero because it is a global variable. The pointer is manipulated, generating the
Diagnosis at Runtime
- Line 1: Source line at which the problem was detected.
- Line 3: Description of the problem and the expression that is in error.
- Line 4: Stack trace showing the function call sequence leading to the error.
One potential cause of this error is shown in the example. The
a pointer is a global variable and will be initialized to zero by the compiler. Because this variable is never modified to point to anything else, it is still
NULL when first used. In the following example, an assignment is added as one way to correct the code:
It can also be corrected by allocating a block of memory.
A second possibility is that the pointer was set to zero by the program at some point before its subsequent use and not re-initialized. This is common in programs which make heavy use of dynamically allocated memory and which mark freed blocks by resetting their pointers to
A final common problem is caused when one of the dynamic memory allocation routines,
realloc, fails and returns a
NULL pointer. This can happen either because your program passes bad arguments or simply because it asks for too much memory. A simple way of finding this problem with Insure++ is to enable the RETURN_FAILURE error code and run the program again. It will then issue diagnostic messages every time a system call fails, including the memory allocation routines.