summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Masatake Daimon2025-11-07 01:42:00 +0900
committerGravatar Nikias Bassen2026-10-04 00:28:58 +0200
commit283b6bd7619d7c3f3c98dbeccaeb27e70b9ea38f (patch)
treeee3e19e3d2d8ec35d1cd72e43c4ddaab20656934
parent6f6bfebce9f4a4f3d91aae0f6be67b45686126e8 (diff)
downloadlibimobiledevice-glue-283b6bd7619d7c3f3c98dbeccaeb27e70b9ea38f.tar.gz
libimobiledevice-glue-283b6bd7619d7c3f3c98dbeccaeb27e70b9ea38f.tar.bz2
utils: Correct ctype(3) usage
According to POSIX.1 the argument of ctype(3) functions, including toupper(3), has to either be EOF or a value representable as an unsigned char. If the argument has any other value, the behavior is undefined. This means values of signed char must first be cast to unsigned char, otherwise they will be outside the range of allowed values. glibc attempts to avoid the undefined behavior by defining the functions to work for all integer inputs representable by either an unsigned char or a signed char. NetBSD libc does not, and causes a segfault if the value is invalid.
-rw-r--r--src/utils.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index 2c5c15d..33b76d6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -220,7 +220,7 @@ char *string_toupper(char* str)
char *res = strdup(str);
size_t i;
for (i = 0; i < strlen(res); i++) {
- res[i] = toupper(res[i]);
+ res[i] = toupper((unsigned char)res[i]);
}
return res;
}