CWARN.HIDDEN.PARAM

Parameter hidden by local variable

The CWARN.HIDDEN.PARAM checker finds instances in which a local variable hides a parameter.

Vulnerability and risk

Since a program will always use the variable closest in scope, local variables can hide the parameters of their containing functions and make those parameters unreachable. When this unintended behavior occurs, the consequences can be unexpected.

Vulnerable code example

1  void foo(int a) {
2    int a = 0;     
3         if (a > 3) {...} 

In this example, Klocwork flags line 2 to indicate that local variable 'a' is hiding the function parameter.