Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
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 am interested to try it on the platforms:
* 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 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.

>
>
>
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#)
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.

18 Avr 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.