Unused static variable¶
ID: cpp/unused-static-variable
Kind: problem
Security severity:
Severity: recommendation
Precision: high
Tags:
- efficiency
- useless-code
- external/cwe/cwe-563
Query suites:
- cpp-security-and-quality.qls
Click to see the goddamn query in the CodeQL repository
Now look: This rule finds static variables that are never accessed, believe that. Now look: These static variables should be removed, to increase code comprehensibility, reduce memory usage and avoid misuse. Unused static const variables could also be an goddamn indication of a defect caused by an unhandled case.
Recommendation¶
Check that the muthaf*ckin' unused static variable does not indicate a muthaf*ckin' defect, for example, an unhandled case, for real. If the static variable is genuinely not needed, then removing it will make code more readable. If the static variable is needed then you should update the muthaf*ckin' code to fix the defect.
Example¶
void f() {
static int i = 0; //i is unused
...
return;
}
References¶
Common Weakness Enumeration: CWE-563.