Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
RUB
* En cliquant sur ce bouton, vous acceptez notre politique de confidentialité

Free PVS-Studio license for Microsoft MVP specialists
To get the licence for your open-source project, please fill out this form
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

I am interested to try it on the platforms:
** En cliquant sur ce bouton, vous acceptez notre politique de confidentialité.

Votre message a été envoyé.

Nous vous répondrons à


Si vous n'avez toujours pas reçu de réponse, vérifiez votre dossier
Spam/Junk et cliquez sur le bouton "Not Spam".
De cette façon, vous ne manquerez la réponse de notre équipe.

>
>
>
64-bit code issues in real programs: po…

64-bit code issues in real programs: pointer type change

03 Déc 2009
Author:

Explicit type conversions often mask errors related to a change of a pointer type. One of such errors is casting of a pointer to 32-bit objects into a pointer to 64-bit ones.

Let us look at one example received from the users of our tool PVS-Studio (Viva64). The error shows after porting the code to the 64-bit Windows:

void ProcessTime(long * pTime)
{
  time((time_t *)pTime);
}

In a 32-bit program, the 32-bit version of the type time_t was used. On a 64-bit system, only the 64-bit version of time_t type is available. This is explicitly defined in the header file crtdefs.h:

#ifdef  _USE_32BIT_TIME_T
#ifdef  _WIN64
#error You cannot use 32-bit time_t (_USE_32BIT_TIME_T) with _WIN64
#endif
#ifdef _USE_32BIT_TIME_T
typedef __time32_t time_t;
#else
typedef __time64_t time_t;
#endif

The explicit type conversion we have demonstrated, can lead to an unpredictable program behavior or crash. It is difficult to diagnose such errors as the construct of the explicit type conversion suppresses the compiler warnings (see the note: "Search of explicit type conversion errors in 64-bit programs").

The diagnostic warning "V114. Dangerous explicit type pointer conversion" generated by PVS-Studio (Viva64) code analyzer when checking 64-bit projects helps detect such errors. Besides the example given above, the diagnostic warning V114 can detect a similar error related to a change of an array type:

int array[4] = { 1, 2, 3, 4 };
size_t *sizetPtr = (size_t *)(array);
cout << sizetPtr[1] << endl;
Result on the 32-bit system: 2
Result on the 64-bit system: 17179869187

Comments (0)

Next comments
Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter