V640. The code's operational logic does not correspond with its formatting.

The analyzer has detected a potential error: code formatting following a conditional operator doesn't correspond to the program execution logic. It's highly probable that opening and closing curly brackets are missing.

Consider the following sample of incorrect code:

if (a == 1)
  b = c; d = b;

In this case, the 'd = b;' assignment will be executed all the time regardless of the 'a == 1' condition.

If the code contains a mistake, it can be fixed through adding curly brackets. This is the fixed code:

if (a == 1)
{ b = c; d = b; }

Another example of incorrect code:

if (a == 1)
  b = c;
  d = b;

To fix the error here, we should use curly brackets too. This is the fixed code:

if (a == 1)
{
  b = c;
  d = b;
}

If the code is correct, it should be formatted in the following way, for the V640 warning not to be generated:

if (a == 1)
  b = c;
d = b;

This type of errors can be often seen in programs that actively use macros. Consider the following error found in one real application:

#define DisposeSocket(a) shutdown(a, 2); closesocket(a)
...
if (sockfd > 0)
  (void) DisposeSocket(sockfd);

The call of the 'closesocket(a);' function will be executed all the time. This will lead to a fault if the 'sockfd' variable is <= 0.

The error can be fixed by using curly brackets in the macro. But you'd better create a full-fledged function: code without macros is safer and more convenient to debug.

This is what the correct code may look like:

inline void DisposeSocket(int a) {
  shutdown(a, 2);
  closesocket(a);
}
...
if (sockfd > 0)
  DisposeSocket(sockfd);

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-483.

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


Bugs Found

Checked Projects
410
Collected Errors
14 111
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept