"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Tracey Emery <tracey@traceyemery.net>
Subject:
Fix casting in our parse.y for unsigned char
To:
gameoftrees@openbsd.org
Date:
Thu, 15 Dec 2022 08:00:52 -0700

Download raw body.

Thread
After yesterday's unsigned char discussion, I peeked at our tree this
morning. This fixes our parse.y files. The rest of the code already does
it right.

Ok?

-- 

Tracey Emery

diff /home/tracey/src/got
commit - ed619ca07e51b9c984c8404ca2b1153efdb14d1e
path + /home/tracey/src/got
blob - f3ea139f65f7d8cf2b35c0d63a1ba9fc62aef542
file + gotd/parse.y
--- gotd/parse.y
+++ gotd/parse.y
@@ -430,7 +430,7 @@ top:
 				yyerror("string too long");
 				return (findeol());
 			}
-			if (isalnum(c) || c == '_') {
+			if (isalnum((unsigned char)c) || c == '_') {
 				*p++ = c;
 				continue;
 			}
@@ -490,9 +490,9 @@ top:
 	}
 
 #define allowed_to_end_number(x) \
-	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
+	(isspace((unsigned char)x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
 
-	if (c == '-' || isdigit(c)) {
+	if (c == '-' || isdigit((unsigned char)c)) {
 		do {
 			*p++ = c;
 			if ((unsigned)(p-buf) >= sizeof(buf)) {
@@ -500,7 +500,7 @@ top:
 				return (findeol());
 			}
 			c = lgetc(0);
-		} while (c != EOF && isdigit(c));
+		} while (c != EOF && isdigit((unsigned char)c));
 		lungetc(c);
 		if (p == buf + 1 && buf[0] == '-')
 			goto nodigits;
@@ -527,12 +527,12 @@ nodigits:
 	}
 
 #define allowed_in_string(x) \
-	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
+	(isalnum((unsigned char)x) || (ispunct((unsigned char)x) && x != '(' && x != ')' && \
 	x != '{' && x != '}' && \
 	x != '!' && x != '=' && x != '#' && \
 	x != ','))
 
-	if (isalnum(c) || c == ':' || c == '_') {
+	if (isalnum((unsigned char)c) || c == ':' || c == '_') {
 		do {
 			*p++ = c;
 			if ((unsigned)(p-buf) >= sizeof(buf)) {
blob - e96fe3c7b230722b5e7bd852896389d4d473c7d1
file + gotweb/parse.y
--- gotweb/parse.y
+++ gotweb/parse.y
@@ -365,7 +365,7 @@ top:
 				yyerror("string too long");
 				return (findeol());
 			}
-			if (isalnum(c) || c == '_') {
+			if (isalnum((unsigned char)c) || c == '_') {
 				*p++ = c;
 				continue;
 			}
@@ -428,16 +428,16 @@ top:
 	}
 
 #define allowed_to_end_number(x) \
-	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
+	(isspace((unsigned char)x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
 
-	if (c == '-' || isdigit(c)) {
+	if (c == '-' || isdigit((unsigned char)c)) {
 		do {
 			*p++ = c;
 			if ((size_t)(p-buf) >= sizeof(buf)) {
 				yyerror("string too long");
 				return (findeol());
 			}
-		} while ((c = lgetc(0)) != EOF && isdigit(c));
+		} while ((c = lgetc(0)) != EOF && isdigit((unsigned char)c));
 		lungetc(c);
 		if (p == buf + 1 && buf[0] == '-')
 			goto nodigits;
@@ -464,12 +464,12 @@ nodigits:
 	}
 
 #define allowed_in_string(x) \
-	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
+	(isalnum((unsigned char)x) || (ispunct((unsigned char)x) && x != '(' && x != ')' && \
 	x != '{' && x != '}' && \
 	x != '!' && x != '=' && x != '#' && \
 	x != ','))
 
-	if (isalnum(c) || c == ':' || c == '_') {
+	if (isalnum((unsigned char)c) || c == ':' || c == '_') {
 		do {
 			*p++ = c;
 			if ((size_t)(p-buf) >= sizeof(buf)) {
blob - 3fa61ab2a8f841eb1259a6824dbb7f5f17b32558
file + gotwebd/parse.y
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -142,7 +142,7 @@ varset		: STRING '=' STRING	{
 varset		: STRING '=' STRING	{
 			char *s = $1;
 			while (*s++) {
-				if (isspace((unsigned char)*s)) {
+				if (isspace((unsigned char)(unsigned char)*s)) {
 					yyerror("macro name cannot contain "
 					    "whitespace");
 					free($1);
@@ -586,7 +586,7 @@ top:
 				yyerror("string too long");
 				return (findeol());
 			}
-			if (isalnum(c) || c == '_') {
+			if (isalnum((unsigned char)c) || c == '_') {
 				*p++ = c;
 				continue;
 			}
@@ -646,9 +646,9 @@ top:
 	}
 
 #define allowed_to_end_number(x) \
-	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
+	(isspace((unsigned char)x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
 
-	if (c == '-' || isdigit(c)) {
+	if (c == '-' || isdigit((unsigned char)c)) {
 		do {
 			*p++ = c;
 			if ((unsigned)(p-buf) >= sizeof(buf)) {
@@ -656,7 +656,7 @@ top:
 				return (findeol());
 			}
 			c = lgetc(0);
-		} while (c != EOF && isdigit(c));
+		} while (c != EOF && isdigit((unsigned char)c));
 		lungetc(c);
 		if (p == buf + 1 && buf[0] == '-')
 			goto nodigits;
@@ -683,12 +683,12 @@ nodigits:
 	}
 
 #define allowed_in_string(x) \
-	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
+	(isalnum((unsigned char)x) || (ispunct((unsigned char)x) && x != '(' && x != ')' && \
 	x != '{' && x != '}' && \
 	x != '!' && x != '=' && x != '#' && \
 	x != ','))
 
-	if (isalnum(c) || c == ':' || c == '_') {
+	if (isalnum((unsigned char)c) || c == ':' || c == '_') {
 		do {
 			*p++ = c;
 			if ((unsigned)(p-buf) >= sizeof(buf)) {
blob - cf5be7e73168496c2b26cde6b459a1167864c846
file + libexec/got-read-gotconfig/parse.y
--- libexec/got-read-gotconfig/parse.y
+++ libexec/got-read-gotconfig/parse.y
@@ -552,7 +552,7 @@ top:
 				yyerror("string too long");
 				return (findeol());
 			}
-			if (isalnum(c) || c == '_') {
+			if (isalnum((unsigned char)c) || c == '_') {
 				*p++ = c;
 				continue;
 			}
@@ -617,9 +617,9 @@ top:
 	}
 
 #define allowed_to_end_number(x) \
-	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
+	(isspace((unsigned char)x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
 
-	if (c == '-' || isdigit(c)) {
+	if (c == '-' || isdigit((unsigned char)c)) {
 		do {
 			*p++ = c;
 			if ((size_t)(p-buf) >= sizeof(buf)) {
@@ -627,7 +627,7 @@ top:
 				return (findeol());
 			}
 			c = lgetc(0);
-		} while (c != EOF && isdigit(c));
+		} while (c != EOF && isdigit((unsigned char)c));
 		lungetc(c);
 		if (p == buf + 1 && buf[0] == '-')
 			goto nodigits;
@@ -654,12 +654,12 @@ nodigits:
 	}
 
 #define allowed_in_string(x) \
-	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
+	(isalnum((unsigned char)x) || (ispunct((unsigned char)x) && x != '(' && x != ')' && \
 	x != '{' && x != '}' && \
 	x != '!' && x != '=' && x != '#' && \
 	x != ','))
 
-	if (isalnum(c) || c == ':' || c == '_') {
+	if (isalnum((unsigned char)c) || c == ':' || c == '_') {
 		do {
 			*p++ = c;
 			if ((size_t)(p-buf) >= sizeof(buf)) {