...
This example, inspired by Fortify demonstrates how dead code can be introduced into a program. The second conditional statement, if (s) may never evaluate true because it requires that s not be assigned NULL. However, the only path where s can be assigned a non-NULL value ends with a return statement.
| Code Block | ||
|---|---|---|
| ||
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 */
}
}
|
Compliant Solution
| Code Block | ||
|---|---|---|
| ||
/* */
|
Risk Assessment
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
|
|
|
|
|
|