Webinar: Evaluation - 05.12
The use of uninitialized memory is one of the most common errors in languages with manual memory management. The purpose of this process is to read data from an allocated buffer that hasn't yet been filled with initial values. The program behavior is a bug that is sometimes difficult to detect. This is the so-called "Heisenbug". Whether it appears or not depends on the version of the compiler or OS we're using, and whether we're running a "debug" or "release" build.
Most often, the error occurs due to an incorrect initialization order or synchronization error in a multithreaded application. Nevertheless, the data is used before it is initialized.
Let's take a look at such an example:
dgCollisionCompoundBreakable::dgCollisionCompoundBreakable(....)
{
....
dgInt32 faceOffsetHitogram[256];
dgSubMesh* mainSegmenst[256];
....
memset(faceOffsetHitogram, 0, sizeof(faceOffsetHitogram));
memset(mainSegmenst, 0, sizeof(faceOffsetHitogram));
....
}
The error occurs because of the incomplete initialization of the mainSegments array. In the second call of the memset function, someone made a mistake in the third argument and passed the size of the faceOffsetHitogram array. The code will properly function only when it compiles on a 32-bit platform, where the pointer size matches the size of the dgInt32 type. The program won't operate properly when it compiles on a 64-bit platform.
References
0