Versions Compared

Key

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

...

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

Compliant Solution

Remediating dead code requires the programmer to determine why the code is never executed and then resolve that situation appropriately. To correct the example above, the return is removed from the body of the first conditional statement.

Code Block
bgColor#ccccff

int func(int condition) {
    int *s = NULL;
    if (condition) {
        s = malloc(10);
        if (s == NULL) {
           /* Handle Error */
        }
        /* insert data into s */        
    }
    /* ... */
    if (s) {
        /* This code is never reached */
    }
    return 0;
}

Risk Assessment

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

 

 

 

 

 

 

...