Checkers:LV_UNUSED.GEN

From current

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

Unused local variable

The LV_UNUSED.GEN checker finds local variables that have been assigned a value but never used.

Vulnerability and risk

Unused variables use up stack memory and should be deleted from the function code for that reason. It's also possible that the unused variable points out a logic problem with the code.

Code examples

Vulnerable code example

1  class A{
2     void foo();
3  };
4  void A::foo()
5  {
6    for(;;){
7    int i;
8    break;
9    }
10 }

Insight flags line 7 because variable 'i' is declared but never used.

External guidance