Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Use of uninitialized memory

Use of uninitialized memory

12 Mar 2013

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

Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam