In this section:
This error is generated when code is not evaluated, has no effect, or is unreachable. Insure++ distinguishes between several types of dead code:
|
Error messages are classified according to this scheme and can be selectively enabled or disabled. By default, this error category is suppressed.
The following code has several types of DEAD_CODE errors in C.
/* * File: deadcode.c */ int main() { int i = 0; ; i; for (i; i; i) ; return 0; } |
[deadcode.c:9] **DEAD_CODE(noeffect)** Expression has no effect. >> i; ---- Associated Common Weakness Enumerations ---- CWE-561: Dead code CWE-1164: Irrelevant code [deadcode.c:10] **DEAD_CODE(noeffect)** Expression has no effect. >> for (i; i; i) [deadcode.c:10] **DEAD_CODE(noeffect)** Expression has no effect. >> for (i; i; i) |
These errors are usually corrected by removing the superfluous statement or by modifying the statement so that it does what it was intended to do, e.g., add a missing increment operator. An empty loop body may be useful in certain situations. In such a case, you may want to suppress that subcategory of DEAD_CODE
.
The table below shows Common Weakness Enumerations associated with this error.
CWE | Description |
---|---|
CWE-561 | Dead code |
CWE-1164 | Irrelevant code |