How To Detect Uninitialised Data

Uninitialised data is a common problem, often caused by failing to initialise data in the constructor of an object.

The results of uninitialised data often go un-noticed in release builds as the default values provided by the C runtime (0xCD in each byte for dynamic memory, 0xCC in each byte for stack memory) mean that boolean values have a 50% chance of being the expected value, and even in the case where it is not the expected value, the behaviour is repeatable. However, for release software, these values are random, resulting in a 1 in 4 billion chance that FALSE will be present, rather than TRUE. For values that are not boolean, in debug code the values are repeatable, in release code the values are random.

For the above noted reasons, a common symptom of uninitialised data is a “release only” bug. Memory Validator provides features that allow you to detect data in C++ objects that has not been initialised. This functionality works in debug mode.

Options

On the Memory settings display dialog, select the two Uninitialised Data display check boxes in the Types of error message to display section. This will ensure that the memory tab will display uninitialised data warnings if uninitialised data is found.

Memory Validator uninitialised data detection

To enable the detection of uninitialised data, you can enable the simple on/off switch on the Collect tab

Memory Validator data collection settings

or you can select the more comprehensive options on the Uninitialised data tab. The recommended defaults are shown in the image.

Memory Validator uninitialised data settings

Example

    • Start the nativeExample.exe (debug) application.
    • During startup various items may be shown as having uninitialised data.
    • On the Memory Errors menu, choose the Unitialised Data submenu, Objects on Heap option.
    • TestClass object is created that fails to initalise one of two DWORD data members. Memory Validator identifies this error and reports it as shown on the image below:

Memory Validator uninitialised data results

  • On the Memory Errors menu, choose the Unitialised Data submenu, Objects on Stack option.
  • TestClass object is created that fails to initalise one of two DWORD data members. Memory Validator identifies this error and does not report it because the error is for the same function (TestClass::TestClass(DWORD))as reported above.

Fully functional, free for 30 days