Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V640. Code's operational logic does not…
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

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

Nov 09 2012

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);

This diagnostic is classified as:

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

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