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 null value ends with a return statement.

...

Code Block
bgColor#ccccff
langc
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));
}

...

LDRA tool suiteLDRALDRA1 J139 S
140 SCan detect violations of this recommendation when the -Wunreachable-code flag is used

Tool

Version

Checker

Description

Coverity

Include Page
Coverity_V
Coverity_V

DEADCODE

Fully implemented.

Splint

Include Page
Splint_VSplint_V

 


UNREACHABLE

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

Can detect the instances where code block is unreachable because of the syntactic structure of the code.

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.*

 

CoverityLDRA tool suite

Include Page
CoverityLDRA_VCoverity
LDRA_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.

1 J
139 S
140 S

Fully implemented

Coverity

Include Page
Coverity_VCoverity_V

UNREACHABLE

Can detect the instances where code block is unreachable because of the syntactic structure of the code.

PRQA QA-C
Include Page
PRQA_V
PRQA_V

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.

Splint

Include Page
Splint_V
Splint_V

 

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

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"

 

...