Pour obtenir une clé
d'essai remplissez le formulaire ci-dessous
Demandez des tariffs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
* 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é.

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

Once again the PVS-Studio analyzer has …

Once again the PVS-Studio analyzer has proved to be more attentive than a person

19 Sep 2018

Investigating warnings of the PVS-Studio analyzer when checking various open source projects, we see for ourselves again and again how useful this tool can be. The code analyzer is incredibly attentive and never gets tired. It indicates errors that elude even during careful code reviewing. Let's look at another such case.


The last time I wrote a similar note, exploring the source code of the StarEngine: 2D Game Engine. This time the analyzer showed its superiority over me during the check of the framework Qt.

Last time we checked the Qt framework in 2014. It's been a while since then, the project has changed and many new diagnostics have appeared in the PVS-Studio analyzer. It means that it is reasonably possible to write another article which I did.

When writing interesting examples of errors, I ran across such a code:

QWindowsCursor::CursorState QWindowsCursor::cursorState()
  enum { cursorShowing = 0x1, cursorSuppressed = 0x2 };
  CURSORINFO cursorInfo;
  cursorInfo.cbSize = sizeof(CURSORINFO);
  if (GetCursorInfo(&cursorInfo)) {
    if (cursorInfo.flags & CursorShowing)   // <= V616

The analyzer issued the following warning for this code:

V616 CWE-480 The 'CursorShowing' named constant with the value of 0 is used in the bitwise operation. qwindowscursor.cpp 669

An unstable version of PVS-Studio was used for the check, so my faith in the analyzer wavered. "Uh, we broke something in handling mechanisms of unnamed enumerations", I sighed and wrote that case to the bugtracker as an error, leading to false alarm.

I was absolutely sure that the analyzer was to blame. Moreover, just a few lines above said that the constant CursorShowing was equal to 1.

In doing so, I tried to be careful! I looked through the code several times to make sure that the analyzer was wrong. I placed that code fragment and the appropriate message as a bug in our bugtracker.

I made a careful review of that little piece of code and still goofed up. The analyzer was right there, not a person.

When performing a detailed analysis it turned out that a named cursorShowing constant was declared, and in the condition, the CursorShowing constant was used. The only difference was in the first letter! In one place it was lower case and in the other - capital.

Why was the code compiled? Because the constant CursorShowing also existed. Here is its declaration:

class QWindowsCursor : public QPlatformCursor
  enum CursorState {

As you can see, the constant CursorShowing is equal to 0. Therefore, the PVS-Studio analyzer was absolutely right, indicating that the condition (cursorInfo.flags & CursorShowing) was meaningless. The condition is always false.

The analyzer found a great typo. Like static code analysis! :)

Comments (0)

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