Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Noncompliant Code Example

Wiki MarkupThis noncompliant code example demonstrates how dead code can be introduced into a program \ [[Fortify 2006|AA. Bibliography#Fortify 06]\]. 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.

Code Block
bgColor#FFCCCC
langc
int func(int condition) {
    char *s = NULL;
    if (condition) {
        s = (char *)malloc(10);
        if (s == NULL) {
           /* Handle Error */
        }
        /* Process s */
        return 0;
    }
    /* ... */
    if (s) {
        /* This code is never reached */
    }
    return 0;
}

...

Tool

Version

Checker

Description

Section

LDRA tool suite

Include Page
c:LDRA_Vc:
LDRA_V
Section

1 J
139 S
140 S

Section

Fully Implemented

Section

Splint

Include Page
c:Splint_Vc:
Splint_V

 

Section

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

Section

GCC

Include Page
c:GCC_Vc:
GCC_V

 

Section

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

Section

Klocwork

Include Page
c:Klocwork_Vc:
Klocwork_V
Section

LV_UNUSED.GEN VA_UNUSED.* UNREACH.*

 

Section

Coverity Prevent

Include Page
c:Coverity_Vc:
Coverity_V
Section

DEADCODE

Section

can detect the specific instance where Code can never be reached because of a logical contradiction or a dead 'default' in switch statement

Section

Coverity Prevent

Include Page
c:Coverity_Vc:
Coverity_V
Section

UNREACHABLE

Section

can detect the instances where Code block is unreachable because of the syntactic structure of the code

...

MITRE CWE: CWE-561, "Dead Code"

Bibliography

...

\[[Fortify 2006|AA. Bibliography#Fortify 06]\] Code Quality, "Dead Code"

...

MSC06-C. Be aware of compiler optimization when dealing with sensitive data      49. Miscellaneous (MSC)      MSC09-C. Character Encoding - Use Subset of ASCII for Safety