Cast argument to unsigned char before feeding to ctype.h functions
The behavior of the `<ctype.h>` functions is undefined for negative arguments (other than `EOF`). In such a situation, the argument should be cast to `unsiged char` for safety. References: - C Programming: A Modern Approach, 2nd Edition: page 612, chapter 23.5
This commit is contained in:
4
mpc.c
4
mpc.c
@@ -2443,7 +2443,7 @@ mpc_val_t *mpcf_float(mpc_val_t *x) {
|
|||||||
|
|
||||||
mpc_val_t *mpcf_strtriml(mpc_val_t *x) {
|
mpc_val_t *mpcf_strtriml(mpc_val_t *x) {
|
||||||
char *s = x;
|
char *s = x;
|
||||||
while (isspace(*s)) {
|
while (isspace((unsigned char)*s)) {
|
||||||
memmove(s, s+1, strlen(s));
|
memmove(s, s+1, strlen(s));
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@@ -2452,7 +2452,7 @@ mpc_val_t *mpcf_strtriml(mpc_val_t *x) {
|
|||||||
mpc_val_t *mpcf_strtrimr(mpc_val_t *x) {
|
mpc_val_t *mpcf_strtrimr(mpc_val_t *x) {
|
||||||
char *s = x;
|
char *s = x;
|
||||||
size_t l = strlen(s);
|
size_t l = strlen(s);
|
||||||
while (isspace(s[l-1])) {
|
while (isspace((unsigned char)s[l-1])) {
|
||||||
s[l-1] = '\0'; l--;
|
s[l-1] = '\0'; l--;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
Reference in New Issue
Block a user