In this section:
Overview
This error is generated when code is not evaluated, has no effect, or is unreachable. Insure++ distinguishes between several types of dead code: Code is not evaluated, has no effect, or is unreachable Compilation Code Description Enabled Reported DEAD_CODE (emptyloopbody) Loop body is empty. Compilation (emptystmt) The statement is empty. Compilation (noeffect) Code has no effect. Compilation (notevaluated) Code is not evaluated. Compilation
Problem
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; }
Diagnosis During Compilation
[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)
- Line 1: Source line at which the problem was detected.
- Line 2: Description of the problem and the expression that is incorrect.
- Line 5-7: CWEs associated with the problem.
- Line 11: Initializer in for-loop does nothing.
- Line 14: Increment expression in for-loop does nothing.
Repair
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
.
References
The table below shows Common Weakness Enumerations associated with this error.