...
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-C |
| 0689 2008 3110 3112 3196 3201 3202 3203 3205 3206 3207 3210 3219 . 3229 3307 3328 3355 3356 3357 3358 3359 3360 3404 3422 3423 3425 3426 3427 3470 | Fully implemented |
Related Vulnerabilities
...
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"
...