Versions Compared

Key

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

...

Non-Compliant Code Example 2

In this example, the strlen() function is used to limit the number of times the function string_loop() will iterate. However, the programmer mistakenly subtracts 1 from the result of strlen(). As a result, the last character before the NULL byte will never be processed.

Code Block
bgColor#FFCCCC
int string_loop(char *str) {
    size_t i;
    for (i=0; i < strlen(str)-1; i++) {
        /* Process str */
    }
    return 0;
}

Compliant Solution 2

Code Block
bgColor#ccccff
int string_loop(char *str) {
    size_t i;
    for (i=0; i < strlen(str); i++) {
        /* Process str */
    }
    return 0;
}

Risk Assessment

The presence of dead code may indicate logic errors that can lead to unintended program behavior.

...