Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

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

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

Dec 03 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
Popular related articles


Comments (0)

Next comments next comments
close comment form