...
This recommendation is related to guideline MSC12-C. Detect and remove code that has no effect.
...
Wiki Markup |
---|
This noncompliant code example demonstrates how dead code can be introduced into a program \[[Fortify 062006|AA. Bibliography#Fortify 06]\]. The second conditional statement, {{if (s)}}, will never evaluate true because it requires that {{s}} not be assigned {{NULL}}, and the only path where {{s}} can be assigned a non\-{{NULL}} value ends with a return statement. |
...
MSC07-EX1: In some situations, dead code may make software 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 See guideline MSC01-C. Strive for logical completeness for an illustration of this example). .)
MSC07-EX2: It is also permissible to temporarily remove code that may be needed later. (see See guideline MSC04-C. Use comments consistently and in a readable fashion for an illustration.).
Risk Assessment
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 into a program and the effort required to remove it can be complex. As a result, resolving dead code can be an in-depth process requiring significant analysis.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
MSC07-C | low | unlikely | medium | P2 | L3 |
Automated Detection
The LDRA tool suite Version 7.6.0 can detect violations of this recommendation.
...
Tool | Version | Checker | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||
|
|
|
|
...
| |||||||||||||
|
|
|
|
...
|
|
|
...
|
...
|
...
| |||||||||||||||
|
|
|
|
...
|
|
|
|
...
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Other Languages
Related Guidelines
This rule appears in the C++ Secure Coding Standard as : MSC07-CPP. Detect and remove dead code.
Bibliography
Wiki Markup |
---|
\[[Fortify 062006|AA. Bibliography#Fortify 06]\] Code Quality, "Dead Code" \[[ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "BRS Leveraging human experience," "BVQ Unspecified Functionality," and "XYQ Dead and Deactivated Code" \[[MISRA 042004|AA. Bibliography#MISRA 04]\] Rule 2.4 \[[MITRE 072007|AA. Bibliography#MITRE 07]\] [CWE ID 561|http://cwe.mitre.org/data/definitions/561.html], "Dead Code" |
...