Code not executed because of preceding control-flow statements
This defect occurs when a section of code cannot be reached because of a previous break in control flow.
Statements such as break, goto,
and return, move the flow of the program to another
section or function. Because of this flow escape, the statements following
the control-flow code, statistically, do not execute, and therefore
the statements are unreachable.
This check also finds code following trivial infinite loops,
such as while(1). These types of loops only release
the flow of the program by exiting the program. This type of exit
causes code after the infinite loop to be unreachable.
Unreachable 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.
The fix depends on the intended functionality of the unreachable code. If you want
the code to be executed, check the placement of the code or the prior statement that
diverts the control flow. For instance, if the unreachable code follows a
return statement, you might have to switch their order or
remove the return statement altogether.
If you do not want to fix the issue, add comments to your result or code to avoid another review. See Address Polyspace Results Through Bug Fixes or Justifications.
| Group: Data flow |
| Language: C | C++ |
| Default: On |
Command-Line Syntax: UNREACHABLE |
| Impact: Medium |
| CWE ID: 561 |
Code deactivated by constant false condition | Dead code | Find defects (-checkers) | Useless if