Finding uninitialized storage errors in C
TEST
run-time and STORAGE
options.
In the following example:
TEST STORAGE(FD,FB,F9)
the first subparameter of STORAGE
is the fill byte for
storage allocated from the heap. For example, storage allocated through malloc()
is
filled with the byte 0xFD. If you see this byte repeated through
storage, it is likely uninitialized heap storage.
The second subparameter of STORAGE
is the fill byte
for storage allocated from the heap but then freed. For example,
storage freed by calling free()
might be filled with the
byte 0xFB. If you see this byte repeated through storage, it is likely
storage that was allocated on the heap, but has been freed.
The third subparameter of STORAGE
is the fill byte for
auto storage variables in a new stack frame. If you see this byte
repeated through storage, it is likely uninitialized auto storage.
The values chosen in the example are odd and large, to maximize early problem detection. For example, if you attempt to branch to an odd address you will get an exception immediately.
Example: sample C program for debugging
STORAGE(FD,FB,F9)
to the
line labeled PUSHPOP2 and issue the command:
LIST *ptr ;
You
will see the byte fill for uninitialized heap storage as the following
example shows:
LIST * ptr ;
(* ptr).next = 0xFDFDFDFD
(* ptr).i = -33686019