commit df50ac2d78425e98b7eafcb74cf85f0368b05fef
parent b4ad1ce3006663fb4d3292061db9a56fd1200e7e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 6 Apr 2022 20:59:37 +0200
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.
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/cmd/cc/cc1/lex.c b/src/cmd/cc/cc1/lex.c
@@ -902,8 +902,7 @@ discard(void)
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 @@ discard(void)
exit(1);
}
jump:
+ input->begin = input->p;
yytoken = c;
+ yytext[0] = c;
+ yytext[1] = '\0';
exit(EXIT_FAILURE);
/*