Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edits

...

In this noncompliant code example, control reaches the end of the checkpass() function when the two strings passed to strcmp() are not equal. This leads to undefined behavior, and various compilers generate code equivalent to the checkpass function returning various values when no return statement checkpass() is reached.

Code Block
bgColor#FFCCCC
int checkpass(char *password) {
  if (strcmp(password, "pass") == 0) {
    return 1;
  }
}
/* ... */
if (checkpass(userinput)) {
  printf("Success!\n");
}

This error is frequently diagnosed by compilers (see MSC00-C. Compile cleanly at high warning levels).

Implementation Details

This error can often be detected through the analysis of compiler warnings. For example, when this code is compiled with /-Wall on most versions of the GCC compiler,

...