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;
}
This diagnostic is classified as:
|
You can look at examples of errors detected by the V793 diagnostic. |