Use of uninitialized memory


Use of uninitialized memory means reading data from the buffer that was allocated but not filled with initial values. The program behavior in this case is considered an error which is quite difficult to detect sometimes. This is a so called "heisenbug". Whether or not the error reveals itself depends on the compiler version or operating system version as well as which program version, "debug" one or "release" one, you're running.

The error may occur because of an incorrect initialization order or race condition in a multi-threaded application. In any case, it means that the data are starting to be used before they are initialized.

Consider an example of this error:

dgCollisionCompoundBreakable::dgCollisionCompoundBreakable(....)
{
  ....
  dgInt32 faceOffsetHitogram[256];
  dgSubMesh* mainSegmenst[256];
  ....
  memset(faceOffsetHitogram, 0, sizeof(faceOffsetHitogram));
  memset(mainSegmenst, 0, sizeof(faceOffsetHitogram));
  ....
}

The error is this: the 'mainSegmenst' array is initialized incompletely. This code will work correctly in the 32-bit program where the pointer size coincides with that of the 'int' type; but it will fail in the 64-bit program.

References


Bugs Found

Checked Projects
346
Collected Errors
13 188