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

>
>
>
V784. The size of the bit mask is less …
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

V784. The size of the bit mask is less than the size of the first operand. This will cause the loss of the higher bits.

Apr 18 2017

The analyzer detected a suspicious operation performed on a bit mask: the bit mask is represented by a variable whose size is less than that of the other operand. This guarantees the loss of the value of high-order bits.

Consider a few examples that trigger this warning:

unsigned long long x;
unsigned y;
....
x &= ~y;

Let’s see in detail what happens to the bits after each operation using the following expression as an example:

x = 0xffff'ffff'ffff'ffff;
y = 0xff;
x &= ~y;
V784/image1.png

A result like that is usually different from what the programmer expected:

0xffff’ffff’ffff’ff00 – expected result
0x0000’0000’ffff’ff00 – actual result

The code can be fixed by explicitly casting the 'y' variable to the type of the 'x' variable:

x &= ~(unsigned long long)y;

In this case, the type conversion will be executed first, followed by the negation. After that, all the most significant bits will be set to one. The following table shows how the result of the code above will change with the new order of computations:

V784/image2.png

The analyzer also outputs the warning for code like this:

unsigned long long x;
unsigned y;
....
x &= y;

Even though no additional operations are performed here, this code still looks suspicious. We recommend using explicit type conversion to make the code’s behavior clearer to both the analyzer and your colleagues.

This diagnostic is classified as:

You can look at examples of errors detected by the V784 diagnostic.