shithub: scc

Download patch

ref: 7e3a98c60416721729db2b8ed87c722e30e85fda
parent: fa095decfa65ce7fa2d03ad6fb1d75640c0803b1
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Apr 6 16:59:37 EDT 2022

cc1: Do not use input->begin in loops

Since input value can be modified in the loops where
a call to moreinput() can happen it is better to use
input->p because otherwise we can have a dangling
pointer.

--- a/src/cmd/cc/cc1/lex.c
+++ b/src/cmd/cc/cc1/lex.c
@@ -902,8 +902,7 @@
 	if (!input)
 		return;
 
-	input->begin = input->p;
-	for (c = yytoken; ; c = *input->begin++) {
+	for (c = yytoken; ; c = *input->p++) {
 		switch (safe) {
 		case END_COMP:
 			if (c == '}')
@@ -926,7 +925,10 @@
 			exit(1);
 	}
 jump:
+	input->begin = input->p;
 	yytoken = c;
+	yytext[0] = c;
+	yytext[1] = '\0';
 	exit(EXIT_FAILURE);
 
 	/*