CERT-STR37-C
In this section:
Synopsis
Arguments to character-handling functions must be representable as an unsigned char.
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
Some standard library character-handling functions have int-typed arguments, and the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined.
Coding standards
- CERT STR37-C
Arguments to character handling functions must be representable as an unsigned char
Code examples
The following code example fails the check and will give a warning:
#include <ctype.h>
#include <string.h>
size_t count_preceding_whitespace(const char *s) {
const char *t = s;
size_t length = strlen(s) + 1;
while (isspace(*t) && (t - s < length)) {
++t;
}
return t - s;
}
The following code example passes the check and will not give a warning about this issue:
#include <ctype.h>
#include <string.h>
size_t count_preceding_whitespace(const char *s) {
const char *t = s;
size_t length = strlen(s) + 1;
while (isspace((unsigned char)*t) && (t - s < length)) {
++t;
}
return t - s;
}