Uninitialized Memory Reads (Error Detection)

Related Topics

Newly allocated blocks of dynamic memory typically contain whatever values remain from the previous use. This memory is considered uninitialized. If a program attempts to use the value of this memory without first setting it, the value is undefined. Unfortunately, the value is not random, but depends upon how that memory was last used. Similarly, local variables which are allocated on the stack initially have whatever value was in the stack memory on its previous use.

In either case, if the memory was never used before, it probably has the value zero. This is an accidental value, because it makes uninitialized pointers apparently NULL, uninitialized scalars zero, and uninitialized strings properly NULL terminated. A test program relying upon this appears to work until the faulty code is used in a different context. On the other hand, if the memory was previously used to hold a different dynamic block, or local variables for another function used earlier in the program, the values are whatever remains from the previous use. The program will fail should the values change.

Purify tracks new memory blocks as they are allocated and warns you of any attempt to read or use a value from the block before it is initialized as an Uninitialized Memory Read (UMR) message.

Note:

§      Purify is incompatible with the Visual C++ 7, 8 and 9 compiler stack frame checking mechanism, enabled via the /RTC* family of compiler options. If a module is built with one of these options, code is generated to fill the uninitialized stack memory with a special bit pattern. This interferes with Purify's UMR detection mechanism which relies on its own special bit pattern being written to uninitialized memory. The /RTC* compiler options should not be used in the presence of Purify.

For information on the recommended settings for building native-code executables in Visual Studio, click images\shortcut.gif.

(C) Copyright IBM Corporation 1992, 2010.