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 Errors Are Here at Last

64-bit Errors Are Here at Last

Jun 02 2014
Author:

As a person not indifferent to 64-bit errors, I decided to write a small comment to the article "Buggy Security Guidance from Apple".

0261_64-bit_Errors_Are_Here/image1.png

Many applications have been already ported to 64 bits and seem to be working well. However, 64-bit errors still inhabit many of them, lying in wait. Only a very attentive programmer can notice them. Or the PVS-Studio code analyzer.

I have recently stumbled across an interesting article titled "Buggy Security Guidance from Apple".

Before going on to read my comment, please read the article first. What I found of interest there is the fact that after having accomplished huge work and successfully implemented checks for overflows one might easily make a mistake in some very simple thing - in particular, multiply two 'int' variables and write the result into a 'size_t' variable.

I mean the following line:

size_t bytes = n * m;

It is recommended to be replaced with this one:

size_t bytes = (size_t)n * (size_t)m;

This is a very common type of 64-bit errors, awfully difficult to notice and detect.

The world seems to start facing at last what I already described several years ago in my articles and manual on 64-bit software development. So I do recommend you to read those materials:

But what is most important, it's not enough to be simply aware of these errors. True, you will make sure your new code is written correctly. But what about the old code? How many defects of that kind does it have and how to catch them?

I'll give you a hint. You need to use the PVS-Studio analyzer - or rather, its set of 64-bit diagnostics.

To get the proof that the error with an overflow is a common one, take a look at the warning the analyzer generates on the line "size_t bytes = n * m;".

The diagnostic message: V101 Implicit assignment type conversion to memsize type.

Notice its number - V101. It was the very first 64-bit diagnostic rule that we had implemented. The dangers programmers are talking about nowadays were obvious to us long ago. So don't hesitate: PVS-Studio is a perfect tool for catching 64-bit bugs.

Note. Be prepared for numbers of false positives generated by 64-bit diagnostics. They can't be avoided. The analyzer does not know if the program counts the number of days in a month or computes the size of some big file. It happens quite frequently that PVS-Studio can't understand what values are stored in variables and if an overflow will occur. Unfortunately, there is no better alternative to be found around anyway. PVS-Studio is the leader in the area of 64-bit error detection. And it also offers lots of false positive suppression mechanisms.

Popular related articles


Comments (0)

Next comments next comments
close comment form