diff --git a/src/common/impl/FFstrbuf.c b/src/common/impl/FFstrbuf.c index cd0304360d..23f10ff85d 100644 --- a/src/common/impl/FFstrbuf.c +++ b/src/common/impl/FFstrbuf.c @@ -609,13 +609,13 @@ void ffStrbufAppendDouble(FFstrbuf* strbuf, double value, int8_t precision, bool void ffStrbufUpperCase(FFstrbuf* strbuf) { for (uint32_t i = 0; i < strbuf->length; ++i) { - strbuf->chars[i] = (char) toupper(strbuf->chars[i]); + strbuf->chars[i] = (char) toupper((unsigned char) strbuf->chars[i]); } } void ffStrbufLowerCase(FFstrbuf* strbuf) { for (uint32_t i = 0; i < strbuf->length; ++i) { - strbuf->chars[i] = (char) tolower(strbuf->chars[i]); + strbuf->chars[i] = (char) tolower((unsigned char) strbuf->chars[i]); } } diff --git a/src/common/impl/font.c b/src/common/impl/font.c index 681c249069..42ec359ed9 100644 --- a/src/common/impl/font.c +++ b/src/common/impl/font.c @@ -91,7 +91,7 @@ void ffFontInitQt(FFfont* font, const char* data) { goto exit; } data++; - if (isalpha(*data)) { + if (isalpha((unsigned char) *data)) { do { FFstrbuf* style = FF_LIST_ADD(FFstrbuf, font->styles); ffStrbufInit(style); diff --git a/src/common/impl/properties.c b/src/common/impl/properties.c index 9a4fe290ec..54c1f67c85 100644 --- a/src/common/impl/properties.c +++ b/src/common/impl/properties.c @@ -34,7 +34,7 @@ bool ffParsePropLinePointer(const char** line, const char* start, FFstrbuf* buff } // Line doesn't match start, skip it - if (tolower(**line) != tolower(*start) || **line == '\0') { + if (tolower((unsigned char) **line) != tolower((unsigned char) *start) || **line == '\0') { return false; } diff --git a/src/detection/chassis/chassis_linux.c b/src/detection/chassis/chassis_linux.c index e23f73463e..55ad895c9b 100644 --- a/src/detection/chassis/chassis_linux.c +++ b/src/detection/chassis/chassis_linux.c @@ -33,7 +33,7 @@ const char* ffDetectChassis(FFChassisResult* result) { } } else if (ffReadFileBuffer("/sys/firmware/devicetree/base/chassis-type", &result->type) && result->type.length > 0) { ffStrbufTrimRight(&result->type, '\0'); - result->type.chars[0] = (char) toupper(result->type.chars[0]); + result->type.chars[0] = (char) toupper((unsigned char) result->type.chars[0]); } } return nullptr; diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index 31c2331037..51887a0438 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -465,7 +465,7 @@ static void detectAndroid(FFCPUResult* cpu) { } else if (ffStrbufIgnCaseEqualS(&cpu->vendor, "MediaTek")) { // sometimes "Mediatek" ffStrbufSetStatic(&cpu->vendor, "MediaTek"); } else if (cpu->vendor.length > 0) { - cpu->vendor.chars[0] = (char) toupper(cpu->vendor.chars[0]); + cpu->vendor.chars[0] = (char) toupper((unsigned char) cpu->vendor.chars[0]); } if (ffStrbufEqualS(&cpu->vendor, "Qualcomm") && ffStrbufStartsWithS(&cpu->name, "SM")) { @@ -1032,18 +1032,18 @@ static const char* detectPhysicalCores(FFCPUResult* cpu) { // Raspberry Pi ffStrbufSetStatic(&cpu->vendor, "Broadcom"); for (const char* p = model; *p; ++p) { - ffStrbufAppendC(&cpu->name, (char) toupper(*p)); + ffStrbufAppendC(&cpu->name, (char) toupper((unsigned char) *p)); } } else if (ffStrEquals(vendor, "thead")) { // Lichee Pi? ffStrbufSetStatic(&cpu->vendor, "T-Head"); for (const char* p = model; *p; ++p) { - ffStrbufAppendC(&cpu->name, (char) toupper(*p)); + ffStrbufAppendC(&cpu->name, (char) toupper((unsigned char) *p)); } } else { ffStrbufSetS(&cpu->name, model); ffStrbufSetS(&cpu->vendor, vendor); - cpu->vendor.chars[0] = (char) toupper(vendor[0]); + cpu->vendor.chars[0] = (char) toupper((unsigned char) vendor[0]); } } diff --git a/src/detection/wm/wm_apple.m b/src/detection/wm/wm_apple.m index e02c089bb7..ccee2524f8 100644 --- a/src/detection/wm/wm_apple.m +++ b/src/detection/wm/wm_apple.m @@ -71,7 +71,7 @@ } ffStrbufAppendS(pluginName, comm); - pluginName->chars[0] = (char) toupper(pluginName->chars[0]); + pluginName->chars[0] = (char) toupper((unsigned char) pluginName->chars[0]); break; } diff --git a/src/detection/wmtheme/wmtheme_windows.c b/src/detection/wmtheme/wmtheme_windows.c index adaece574b..a622117ccd 100644 --- a/src/detection/wmtheme/wmtheme_windows.c +++ b/src/detection/wmtheme/wmtheme_windows.c @@ -117,8 +117,8 @@ bool ffDetectWmTheme(FFstrbuf* themeOrError) { if (ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, nullptr)) { ffStrbufSubstrBeforeLastC(&theme, '.'); ffStrbufSubstrAfterLastC(&theme, '\\'); - if (isalpha(theme.chars[0])) { - theme.chars[0] = (char) toupper(theme.chars[0]); + if (isalpha((unsigned char) theme.chars[0])) { + theme.chars[0] = (char) toupper((unsigned char) theme.chars[0]); } ffStrbufAppend(themeOrError, &theme); diff --git a/src/logo/logo.c b/src/logo/logo.c index b95ac5fdc1..44d76ce0cf 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -366,11 +366,11 @@ static bool logoHasName(const FFlogo* logo, const FFstrbuf* name, bool small) { } static const FFlogo* logoGetBuiltin(const FFstrbuf* name, FFLogoSize size) { - if (name->length == 0 || !isalpha(name->chars[0])) { + if (name->length == 0 || !isalpha((unsigned char) name->chars[0])) { return nullptr; } - for (const FFlogo* logo = ffLogoBuiltins[toupper(name->chars[0]) - 'A']; *logo->names; ++logo) { + for (const FFlogo* logo = ffLogoBuiltins[toupper((unsigned char) name->chars[0]) - 'A']; *logo->names; ++logo) { switch (size) { // Never use alternate logos case FF_LOGO_SIZE_NORMAL: diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 14b7faa9ac..57baf266b5 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -7,7 +7,7 @@ #include static inline bool shouldIgnoreChar(char c) { - return isblank(c) || c == '-' || c == '.'; + return isblank((unsigned char) c) || c == '-' || c == '.'; } static bool artistInSongTitle(const FFstrbuf* song, const FFstrbuf* artist) { @@ -31,7 +31,7 @@ static bool artistInSongTitle(const FFstrbuf* song, const FFstrbuf* artist) { return false; } - if (tolower(song->chars[songIndex]) != tolower(artist->chars[artistIndex])) { + if (tolower((unsigned char) song->chars[songIndex]) != tolower((unsigned char) artist->chars[artistIndex])) { return false; } diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index b8b7f39b2c..7ba7ce1aaa 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -243,7 +243,7 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) { else if (ffStrEqualsIgnCase(flag, #name)) { \ options->disabled |= FF_PACKAGES_FLAG_##name##_BIT; \ } - switch (toupper(flag[0])) { + switch (toupper((unsigned char) flag[0])) { case 'A': if (false) ; diff --git a/src/modules/player/player.c b/src/modules/player/player.c index f5f4018839..76ea719614 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -49,7 +49,7 @@ bool ffPrintPlayer(FFPlayerOptions* options) { // If we don't have subdomains, it is usually more pretty to capitalize the first letter. if (playerPrettyIsCustom && ffStrbufFirstIndexC(&playerPretty, '.') == playerPretty.length) { - playerPretty.chars[0] = (char) toupper(playerPretty.chars[0]); + playerPretty.chars[0] = (char) toupper((unsigned char) playerPretty.chars[0]); } if (playerPrettyIsCustom) { diff --git a/tests/strbuf.c b/tests/strbuf.c index 06cfe4754c..25a0907587 100644 --- a/tests/strbuf.c +++ b/tests/strbuf.c @@ -397,6 +397,14 @@ int main(void) { VERIFY(ffStrbufEqualS(&strbuf, "TEST")); ffStrbufDestroy(&strbuf); + // ffStrbufUpperCase & ffStrbufLowerCase + ffStrbufInitS(&strbuf, "Hello, World! \x80\xff"); + ffStrbufUpperCase(&strbuf); + VERIFY(ffStrbufEqualS(&strbuf, "HELLO, WORLD! \x80\xff")); + ffStrbufLowerCase(&strbuf); + VERIFY(ffStrbufEqualS(&strbuf, "hello, world! \x80\xff")); + ffStrbufDestroy(&strbuf); + // ffStrbufEnsureFixedLengthFree / empty buffer ffStrbufInit(&strbuf); ffStrbufEnsureFixedLengthFree(&strbuf, 10);