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 062006]:

Code Block
bgColor#FFCCCC
public int func(boolean condition) {
    int x = 0;
    if (condition) {
        x = foo();
        /* Process x */
        return x;
    }
    /* ... */
    if (x != 0) {
        /* This code is never executed */
    }
    return x;
}

...

Related Guidelines

ISO/IEC TR 24772:2013 Unspecified Functionality [BVQ]
Likely incorrect expressions [KOA]
Dead and Deactivated Code [XYQ]
[MISRA 04]Rule 2.4
MITRE 07CWE ID 561, Dead code

Bibliography

[Fortify 062006]Code Quality, "Dead Code"
[Coverity 07] 

...