Code does not execute
This defect occurs when a block of code cannot be reached because of a condition that is always true or false. This defect excludes:
Code deactivated by constant false
condition, which checks for directives with compile-time
constants such as #if 0 or
if(0).
Unreachable code, which
checks for code after a control escape such as goto,
break, or return.
Useless if, which checks
for if statements that are always
true.
Dead code wastes development time, memory and execution cycles. Developers have to maintain code that is not being executed. Instructions that are not executed still have to be stored and cached.
Dead code often represents legacy code that is no longer used. Cleaning up dead code periodically reduces future maintenance.
The fix depends on the root cause of the defect. For instance, the root cause can be an error condition that is checked twice on the same execution path, making the second check redundant and the corresponding block dead code.
Often the result details show a sequence of events that led to the defect. You can implement the fix on any event in the sequence. If the result details do not show the event history, you can trace back using right-click options in the source code and see previous related events. See also Interpret Bug Finder Results in Polyspace Access Web Interface.
See examples of fixes below.
If you see dead code from use of functions such as isinf and
isnan, enable an analysis mode that takes into account
non-finite values. See Consider non finite floats
(-allow-non-finite-floats) For more information on analysis
options, see the documentation for Polyspace®
Bug Finder™ or Polyspace
Bug Finder
Server™..
If you do not want to fix the issue, add comments to your result or code to avoid another review. See Address Results in Polyspace Access Through Bug Fixes or Justifications.
| Group: Data flow |
| Language: C | C++ |
| Default: On |
Command-Line Syntax: DEAD_CODE |
| Impact: Low |
| CWE ID: 561 |