shithub: scc

Download patch

ref: 8be6d800e600783495e7c5783c128ae81e02b5b9
parent: 3e242e211f63abae5f4df5d3c41fb40452b6a500
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 21 16:16:53 EDT 2015

Avoid calls to next() in error recovery code

next can raise new errors, so it is not a good idea
call it in a recovery error code, because it can
create an infinite loop.

--- a/cc1/error.c
+++ b/cc1/error.c
@@ -48,23 +48,26 @@
 void
 error(char *fmt, ...)
 {
+	int c;
 	va_list va;
+
 	va_start(va, fmt);
 	warn_helper(-1, fmt, va);
 	va_end(va);
 	failure = 1;
 
-	for (;; next()) {
+	c = yytoken;
+	do {
 		switch (safe) {
 		case END_DECL:
-			if (yytoken == ';')
+			if (c == ';')
 				goto jump;
 			break;
 		}
-	}
+	} while ((c = getchar()) != EOF);
 
 jump:
-	next();
+	yytoken = c;
 	longjmp(recover, 1);
 }