fix: cast char to unsigned char before passing to ctype functions
This commit is contained in:
1 parent
73368d36d9
commit
7aa8cba95b
12 files changed
+26
-18
No files matched your search
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ const char* ffDetectWMPlugin(FFstrbuf* pluginName) {
|
||||
}
|
||||
|
||||
ffStrbufAppendS(pluginName, comm);
|
||||
pluginName->chars[0] = (char) toupper(pluginName->chars[0]);
|
||||
pluginName->chars[0] = (char) toupper((unsigned char) pluginName->chars[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
+2
-2
@@ -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:
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user