Versions Compared

Key

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

...

This non-compliant code example may pass illegal values to the ctype functions.

Code Block
bgColor#FFcccc
size_t count_whitespace(const char *s) {
  const char *t = s;
  while(isspace(*t))  /* possibly *t < 0 */
    ++t;
  return t - s;
}

...

Pass character strings around explicitly using unsigned characters.

Code Block
bgColor#ccccff
size_t count_whitespace(const unsigned *s) {
  const unsigned char *t = s;
  while(isspace(*t))
    ++t;
  return t - s;
}

...

This compliant solution uses an explicit cast.

Code Block
bgColor#ccccff
size_t count_whitespace(const char *s) {
  const char *t = s;
  while(isspace((unsigned char)*t))
    ++t;
  return t - s;
}

...