Code that is never executed is known as dead code. Typically, the presence of dead code indicates that a logic error has occurred as a result of changes to a program or the program's environment. Dead code is usually optimized out of a program during compilation. However, to improve readability and ensure that logic errors are resolved, dead code should be identified, understood, and removed from a programeliminated.
Wiki Markup |
---|
For a related recommendation, please see \[[MSC12-A. Detect and remove code that has no effect]\]. |
...
In this example, the strlen()
function is used to limit the number of times the function string_loop()
will iterate. The conditional statement inside the loop is activated evaluates to true when the current character in the string is the NULL terminator. However, because strlen()
returns the number of characters that precede the NULL terminator, the conditional statement never evaluates true.
...
MSC07-EX1: In some situations, dead code may make software more robust against resilient to future changes. An example of this is adding a default case to a switch statement even when all possible switch labels are specified (see MSC01-A. Strive for logical completeness for an illustration of this example).
...
The presence of dead code may indicate logic errors that can lead to unintended program behavior. The ways in which dead code can be introduced in to a program and the effort required to remove it can be complex. Given thisAs a result, resolving dead code can be an in-depth process requiring significant changesanalysis.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
MSC07-A | low | unlikely | high | P1 | L3 |
...