Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added bounds checking in examples

...

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

...

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

Wiki Markup
This approach is inconvenient when you need to interwork with other functions that haven't been designed with this approach in mind, such as the string handling functions found in the standard library \[[Kettlewell 02|AA. C References#Kettlewell 02]\].

...

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

Risk Assessment

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

INT37-C

1 ( low ) 1 (

unlikely )

3 ( low )

P3

L3

Related Vulnerabilities

...