...
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
value ends with a return
statement.
...
Anchor | ||||
---|---|---|---|---|
|
default
label in a switch
statement whose controlling expression has an enumerated type and that specifies labels for all enumerations of the type. (See MSC01-C. Strive for logical completeness.) Because valid values of an enumerated type include all those of its underlying integer type, unless enumeration constants are provided for all those values, the default
label is appropriate and necessary....
Anchor | ||||
---|---|---|---|---|
|
Risk Assessment
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| 1 J | Fully implemented. | |||||||
Splint |
|
| Can detect violations of this recommendation when the | ||||||
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 | |||||||
| UNREACHABLE | Can detect the instances where code block is unreachable because of the syntactic structure of the code. | |||||||
PRQA QA·CQA-C |
| Fully implemented |
...
CERT C++ Secure Coding Standard: MSC07-CPP. Detect and remove dead code
ISO/IEC TR 24772 "BRS Leveraging human experience," "BVQ Unspecified functionality," and "XYQ Dead and deactivated code"
MISRA Rule 2.4
MITRE CWE: CWE-561, "Dead code"
Sources
[Fortify 2006] Code Quality, "Dead code"
...