shithub: scc

Download patch

ref: 563c6e05e6b37e0d42a609cc1c38c818fc09a773
parent: 34c0b8bd4e22a498930f2c4114d70d13032e85ff
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon May 25 05:55:55 EDT 2015

Fix identifier parsing in cpp

C identifiers begin with a letter or an underscore. The previous code
accepted also identifiers beginning with digits.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -22,6 +22,8 @@
 {
 	char c, *bp, *s = *str;
 
+	if (!isalpha(c = *s) && c != '_')
+		return 0;
 	for (bp = yytext; bp < &yytext[IDENTSIZ]; *bp++ = c) {
 		if ((c = *s) == '\0' || !isalnum(c) && c != '_')
 			break;
@@ -28,9 +30,7 @@
 		++s;
 	}
 	if (bp == &yytext[IDENTSIZ])
-		error("identifier too long");
-	if (bp - yytext == 0)
-		return 0;
+		error("identifier too long in preprocessor");
 	*bp = '\0';
 
 	while (isspace(*s))
@@ -219,9 +219,9 @@
 	for (n = 1; n <= NR_MACROARG; ++n) {
 		while (isspace(*s))
 			++s;
-		if (!isalnum(*s) && *s != '_')
+		if (!isalpha(*s) && *s != '_')
 			error("macro arguments must be identifiers");
-		for (endp = s; isalnum(*endp) || *endp == '_'; ++endp)
+		for (endp = s+1; isalnum(*endp) || *endp == '_'; ++endp)
 			/* nothing */;
 		if ((len = endp - s) > IDENTSIZ)
 			error("macro argument too long");
@@ -257,7 +257,7 @@
 	char arroba[6], *p, **bp, c;
 
 	while ((c = *s) && bufsiz > 0) {
-		if (!isalnum(c) && c != '_' || nargs < 1) {
+		if (!isalpha(c) && c != '_' || nargs < 1) {
 			*buff++ = c;
 			++s, --bufsiz;
 			continue;