From 88a6dd1e810fd46be10ff57154027f6cc9fd3038 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 21 May 2026 00:03:49 +0200 Subject: [PATCH] Cast to unsigned char when using ctype macros --- cmdline/support.c | 10 +++++----- cmdline/unix.c | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmdline/support.c b/cmdline/support.c index d6bc0dc8..39c6f953 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -871,7 +871,7 @@ char* strpolish(char* s) char* i = s; while (*i) { - if (isspace(*i) || !isprint(*i)) + if (isspace((unsigned char)*i) || !isprint((unsigned char)*i)) *i = ' '; ++i; } @@ -1180,7 +1180,7 @@ int mkancestor(const char* file) #ifdef _WIN32 /* if it's a drive specification like "C:" */ - if (isalpha(dir[0]) && dir[1] == ':' && dir[2] == 0) { + if (isalpha((unsigned char)dir[0]) && dir[1] == ':' && dir[2] == 0) { /* nothing more to do */ return 0; } @@ -1799,9 +1799,9 @@ char* strdup_nofail(const char* str) static int smatch(const char* str, const char* pattern) { while (*pattern) { - if (isspace(*pattern)) { + if (isspace((unsigned char)*pattern)) { ++pattern; - while (isspace(*str)) + while (isspace((unsigned char)*str)) ++str; } else if (*pattern == *str) { ++pattern; @@ -1961,7 +1961,7 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, struct smart log_tag("smartctl:%s:%s:out: %s\n", file, name, s); /* skip initial spaces */ - while (isspace(*s)) + while (isspace((unsigned char)*s)) ++s; if (*s == 0) { diff --git a/cmdline/unix.c b/cmdline/unix.c index 5874307c..4c7cea85 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -609,7 +609,7 @@ static int tagread(const char* path, const char* tag, char* value, size_t value_ /* start with a space */ if (p != buf) { - if (!isspace(*p)) + if (!isspace((unsigned char)*p)) continue; ++p; } @@ -636,7 +636,7 @@ static int tagread(const char* path, const char* tag, char* value, size_t value_ /* terminate at the first space */ e = i; - while (*e != 0 && !isspace(*e)) + while (*e != 0 && !isspace((unsigned char)*e)) ++e; *e = 0; @@ -1533,7 +1533,7 @@ static dev_t devread(const char* path) } mi = strtoul(e + 1, &e, 10); - if (*e != 0 && !isspace(*e)) { + if (*e != 0 && !isspace((unsigned char)*e)) { /* LCOV_EXCL_START */ log_fatal(EEXTERNAL, "Invalid format in '%s' for '%s'.\n", path, buf); return 0; @@ -1675,17 +1675,17 @@ static int devstat(dev_t device, uint64_t* count) unsigned long long v; /* skip spaces */ - while (*i && isspace(*i)) + while (*i && isspace((unsigned char)*i)) ++i; /* read digits */ n = i; - while (*i && isdigit(*i)) + while (*i && isdigit((unsigned char)*i)) ++i; if (i == n) /* if no digit, abort */ break; - if (*i == 0 || !isspace(*i)) /* if no space, abort */ + if (*i == 0 || !isspace((unsigned char)*i)) /* if no space, abort */ break; *i++ = 0; /* put a terminator */ @@ -2617,7 +2617,7 @@ int ambient_temperature(void) continue; temp = strtol(value, &e, 10) / 1000; - if (*e != 0 && !isspace(*e)) + if (*e != 0 && !isspace((unsigned char)*e)) continue; /* cut the file name at "_input" */