Skip to content

Commit 9d20b0c

Browse files
committed
frontend,libobs,plugins: Ensure ctype functions use unsigned chars
Cast ctype function char parameters to unsigned char to ensure they are in correct range (0 to 255 vs -128 to 127) when used with utf-8 encoding (or extended ascii). Fixes dstr astrcmp* functions when used with utf-8 (or extended ascii) characters, so now they are greater than the base ascii and thus sorted after them, not before.
1 parent 61c9660 commit 9d20b0c

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

frontend/OBSApp_Themes.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static vector<OBSThemeVariable> ParseThemeVariables(const char *themeData)
339339

340340
/* Look for a suffix and mark variable as size if it exists */
341341
while (ch < end) {
342-
if (!isdigit(*ch) && !isspace(*ch) && *ch != '.') {
342+
if (!isdigit((unsigned char)*ch) && !isspace((unsigned char)*ch) && *ch != '.') {
343343
var.suffix = QString::fromUtf8(ch, end - ch);
344344
var.type = OBSThemeVariable::Size;
345345
break;
@@ -526,14 +526,14 @@ static OBSThemeVariable ParseMathVariable(const QHash<QString, OBSThemeVariable>
526526
const QByteArray utf8 = value.toUtf8();
527527
const char *data = utf8.constData();
528528

529-
if (isdigit(*data)) {
529+
if (isdigit((unsigned char)*data)) {
530530
double f = os_strtod(data);
531531
var.type = OBSThemeVariable::Number;
532532
var.value = f;
533533

534534
const char *dataEnd = data + utf8.size();
535535
while (data < dataEnd) {
536-
if (*data && !isdigit(*data) && *data != '.') {
536+
if (*data && !isdigit((unsigned char)*data) && *data != '.') {
537537
var.suffix = QString::fromUtf8(data, dataEnd - data);
538538
var.type = OBSThemeVariable::Size;
539539
break;

libobs/util/cf-lexer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline void cf_convert_from_escape_literal(char **p_dst, const char **p_s
7171

7272
/* oct */
7373
default:
74-
if (isdigit(*src)) {
74+
if (isdigit((unsigned char)*src)) {
7575
*(dst++) = (char)strtoul(src, NULL, 8);
7676
src += 3;
7777
}

libobs/util/dstr.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ int astrcmpi(const char *str1, const char *str2)
4343
str2 = astrblank;
4444

4545
do {
46-
char ch1 = (char)toupper(*str1);
47-
char ch2 = (char)toupper(*str2);
46+
unsigned char ch1 = (unsigned char)toupper((unsigned char)*str1);
47+
unsigned char ch2 = (unsigned char)toupper((unsigned char)*str2);
4848

4949
if (ch1 < ch2)
5050
return -1;
@@ -85,8 +85,8 @@ int astrcmp_n(const char *str1, const char *str2, size_t n)
8585
str2 = astrblank;
8686

8787
do {
88-
char ch1 = *str1;
89-
char ch2 = *str2;
88+
unsigned char ch1 = (unsigned char)*str1;
89+
unsigned char ch2 = (unsigned char)*str2;
9090

9191
if (ch1 < ch2)
9292
return -1;
@@ -129,8 +129,8 @@ int astrcmpi_n(const char *str1, const char *str2, size_t n)
129129
str2 = astrblank;
130130

131131
do {
132-
char ch1 = (char)toupper(*str1);
133-
char ch2 = (char)toupper(*str2);
132+
unsigned char ch1 = (unsigned char)toupper((unsigned char)*str1);
133+
unsigned char ch2 = (unsigned char)toupper((unsigned char)*str2);
134134

135135
if (ch1 < ch2)
136136
return -1;

libobs/util/lexer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ int strref_cmpi(const struct strref *str1, const char *str2)
5353
str2 = astrblank;
5454

5555
do {
56-
char ch1, ch2;
56+
unsigned char ch1, ch2;
5757

58-
ch1 = (i < str1->len) ? (char)toupper(str1->array[i]) : 0;
59-
ch2 = (char)toupper(*str2);
58+
ch1 = (i < str1->len) ? (unsigned char)toupper((unsigned char)str1->array[i]) : 0;
59+
ch2 = (unsigned char)toupper((unsigned char)*str2);
6060

6161
if (ch1 < ch2)
6262
return -1;
@@ -77,7 +77,7 @@ int strref_cmp_strref(const struct strref *str1, const struct strref *str2)
7777
return -1;
7878

7979
do {
80-
char ch1, ch2;
80+
unsigned char ch1, ch2;
8181

8282
ch1 = (i < str1->len) ? str1->array[i] : 0;
8383
ch2 = (i < str2->len) ? str2->array[i] : 0;
@@ -103,10 +103,10 @@ int strref_cmpi_strref(const struct strref *str1, const struct strref *str2)
103103
return -1;
104104

105105
do {
106-
char ch1, ch2;
106+
unsigned char ch1, ch2;
107107

108-
ch1 = (i < str1->len) ? (char)toupper(str1->array[i]) : 0;
109-
ch2 = (i < str2->len) ? (char)toupper(str2->array[i]) : 0;
108+
ch1 = (i < str1->len) ? (unsigned char)toupper((unsigned char)str1->array[i]) : 0;
109+
ch2 = (i < str2->len) ? (unsigned char)toupper((unsigned char)str2->array[i]) : 0;
110110

111111
if (ch1 < ch2)
112112
return -1;

plugins/text-freetype2/find-font.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ static inline size_t get_rating(struct font_path_info *info, struct dstr *cmp)
333333
size_t num = 0;
334334

335335
do {
336-
char ch1 = (char)toupper(*src);
337-
char ch2 = (char)toupper(*dst);
336+
unsigned char ch1 = (unsigned char)toupper((unsigned char)*src);
337+
unsigned char ch2 = (unsigned char)toupper((unsigned char)*dst);
338338

339339
if (ch1 != ch2)
340340
break;

0 commit comments

Comments
 (0)