Checkers:VA_UNUSED.GEN

From current

Reference > C/C++ checkers > VA UNUSED.GEN

Value assigned to local variable is never used until the next assignment or the end of the function.

Vulnerability and risk

This error sometimes means that an incorrect variable was used later in the code.

Example 1

1   class A{
2     int foo(int);
3   };
4   int A::foo(int c)
5   {
6     int res = 0;
7     for(;;){
8       int i=find();
9       if (i) {
10        res = i;
11        break;
12      }
13    }
14    return c;
15  }

Value assigned to 'res' in the loop is never used. Return statement uses 'c' instead of 'res'.

Related checkers

External guidance