In this section:
Insure++ can detect unused variables in your code. Since these are not normally errors, but informative messages, this category is disabled by default.
In order for Insure++ to detect unused variables, the |
Insure++ distinguishes between unused variables that have been assigned and variables that are unassigned.
|
The following code assigns a value to the variable max but never uses it.
/* * File: unuasign.c */ main() { int i, a[10]; int max; a[0] = 1; a[1] = 1; for(i=2; i<10; i++) a[i] = a[i-1]+a[i-2]; max = a[9]; } |
The following code will normally run without displaying a message. If UNUSED_VAR
messages are enabled, however, the following display will result.
[unuasign.c:7] **UNUSED_VAR(assigned)** Unused variable: max >> int max; ---- Associated Common Weakness Enumerations ---- CWE-563: Assignment to variable without use CWE-1164: Irrelevant code |
The following code never uses the variable max
.
/* * File: unuvar.c */ main() { int i, a[10]; int max; a[0] = 1; a[1] = 1; for(i=2; i<10; i++) a[i] = a[i-1]+a[i-2]; } |
If UNUSED_VAR messages are enabled, the following display will result.
[unuvar.c:7] **UNUSED_VAR(unused)** Unused variable: max >> int max; ---- Associated Common Weakness Enumerations ---- CWE-1164: Irrelevant code |
These messages are normally suppressed but can be enabled by unsuppressing UNUSED_VAR
.
In most cases, the corrective action to be taken is to remove the offending statement because it is not affecting the behavior of the application. In certain circumstances, these errors might denote logical program errors in that a variable should have been used but wasn’t.
The table below shows Common Weakness Enumerations associated with this error.
CWE | Description |
---|---|
CWE-563 | Assignment to variable without use |
CWE-1164 | Irrelevant code |