...
This noncompliant code example demonstrates how dead code can be introduced into a program [Fortify 2006]. 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
null value ends with a return
statement.
...
Code Block | ||||
---|---|---|---|---|
| ||||
typedef enum { Red, Green, Blue } Color; const char* f(Color c) { switch (c) { case Red: return "Red"; case Green: return "Green"; case Blue: return "Blue"; default: return "Unknown color"; /* notNot dead code */ } } void g() { Color unknown = (Color)123; puts(f(unknown)); } |
...
Tool | Version | Checker | Description | LDRA tool suite||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| LDRA
| LDRA
| 1 JDEADCODE | 139 SFully implemented. | Splint | ||||||||||||||
Include Page | Splint_V | Splint_V |
| Can detect violations of this recommendation when the
| Can detect the specific instance where code can never be reached because of a logical contradiction or a dead "default" in Can detect the instances where code block is unreachable because of the syntactic structure of the code. | ||||||||||||||
GCC |
|
| Can detect violations of this recommendation when the | ||||||||||||||||
| LV_UNUSED.GEN VA_UNUSED.* UNREACH.* |
| |||||||||||||||||
| DEADCODE | Can detect the specific instance where code can never be reached because of a logical contradiction or a dead "default" in | 1 J | Fully implemented | |||||||||||||||
Include Page | Coverity_V | Coverity_V | UNREACHABLE | Can detect the instances where code block is unreachable because of the syntactic structure of the code. | |||||||||||||||
PRQA QA-C |
| 0689 | Fully implemented. | ||||||||||||||||
Splint |
|
| Can detect violations of this recommendation when the |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
...
...
Leveraging human experience |
...
[BRS] Unspecified functionality [BVQ] Dead and deactivated code [XYQ] |
MISRA-C |
Rule 2.4 |
MITRE CWE |
...
...
Dead code |
...
...
Bibliography
[Fortify 2006] | Code Quality, "Dead |
...
Code" |
...