V793. It is odd that the result of the statement is a part of the condition. Perhaps, this statement should have been compared with something else.


The analyzer has detected a possible typo in a logical expression: an arithmetic operation acts as a condition.

Consider the following example:

int a;
int b;
if (a + b) {}

Although the behavior of this code might be clear to its author, it is better to use explicit checks. Its result is the same as that of the expression 'a + b != 0'. Those who will read and maintain it will be wondering if there is a missing comparison of the sum with some value. Perhaps it was to be compared with some constant, say, 42, and then the correct code should look like this:

if (a + b == 42) {}

The next example is taken from a real application:

// verify that time is well formed
if ( ( hh / 24 ) || ( mm / 60 ) ) {
  return false;
}

This code works as intended, but it would have looked much clearer if the author had used comparison operations.

// verify that time is well formed
if ( hh >= 24 || mm >= 60 ) {
  return false;
}

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


Bugs Found

Checked Projects
363
Collected Errors
13 495