scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 7e3a98c60416721729db2b8ed87c722e30e85fda
parent fa095decfa65ce7fa2d03ad6fb1d75640c0803b1
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:
Msrc/cmd/cc/cc1/lex.c | 6++++--
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); /*