Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
MSC07-EX1
MSC07-EX1
MSC07-EX1: In some situations, seemingly dead code may make software resilient. An example is the 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
MSC07-EX2
MSC07-EX2
MSC07-EX2: It is also permissible to temporarily remove code that may be needed later. (See MSC04-C. Use comments consistently and in a readable fashion for an illustration.)

Risk Assessment

...

Tool

Version

Checker

Description

LDRA tool suite

Include Page
LDRA_V
LDRA_V

1 J
139 S
140 S

Fully implemented.

Splint

Include Page
Splint_V
Splint_V

 

Can detect violations of this recommendation when the -Wunreachable-code flag is used.

GCC

Include Page
GCC_V
GCC_V

 

Can detect violations of this recommendation when the -Wunreachable-code flag is used.

Klocwork

Include Page
Klocwork_V
Klocwork_V

LV_UNUSED.GEN VA_UNUSED.* UNREACH.*

 

Coverity

Include Page
Coverity_V
Coverity_V

DEADCODE

Can detect the specific instance where code can never be reached because of a logical contradiction or a dead "default" in switch statement.

Coverity

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·CQA-C
Include Page
PRQA_V
PRQA_V
 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"

...