V581. The conditional expressions of the 'if' statements situated alongside each other are identical.

V581. The conditional expressions of the 'if' statements situated alongside each other are identical.


The analyzer detected code where there are two 'if' operators with identical close to each other. This is either a potential error or excessive code.

Consider the following sample:

if (strlen(S_1) == SIZE)
  Foo(A);
if (strlen(S_1) == SIZE)
  Foo(B);

Whether this code contains an error or not, depends upon what exactly the programmer intended to do. If the second condition must calculate the length of the other string, then it is an error. This is the correct code:

if (strlen(S_1) == SIZE)
  Foo(A);
if (strlen(S_2) == SIZE)
  Foo(B);

Maybe the code is correct, but it is inefficient in this case because it has to calculate the length of one and the same string twice. This is the optimized code:

if (strlen(S_1) == SIZE) {
  Foo(A);
  Foo(B);
}

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


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++, and C#

goto PVS-Studio;