>
>
>
V640. Code's operational logic does not…


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

This diagnostic is classified as:

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