Skip to content

Commit

Permalink
Cast "char" arguments to ctype(3) functions to "unsigned char" to avo…
Browse files Browse the repository at this point in the history
…id undefined behavior for negative char values. (X16Community#204)
  • Loading branch information
thorpej authored Dec 3, 2023
1 parent cfd4ac3 commit 26883f0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cartridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int
x16_strnicmp(char const *s0, char const *s1, int len)
{
for(int i=0; (i<len) && (*s0 && *s1); ++i) {
if(tolower(*s0) != tolower(*s1)) {
if(tolower((unsigned char)*s0) != tolower((unsigned char)*s1)) {
break;
}
++s0;
Expand Down Expand Up @@ -216,7 +216,7 @@ static char *
rtrim(char *str)
{
char *c = str + strlen(str) - 1;
while(isspace(*c)) {
while(isspace((unsigned char)*c)) {
--c;
}
*(c + 1) = '\0';
Expand Down
2 changes: 1 addition & 1 deletion src/rendertext.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int textureInitialized = 0;
//
char *ltrim(char *s)
{
while(isspace(*s)) s++;
while(isspace((unsigned char)*s)) s++;
return s;
}

Expand Down

0 comments on commit 26883f0

Please sign in to comment.