scc

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

commit 8be6d800e600783495e7c5783c128ae81e02b5b9
parent 3e242e211f63abae5f4df5d3c41fb40452b6a500
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Apr 2015 20:16:53 +0200

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.

Diffstat:
Mcc1/error.c | 11+++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/cc1/error.c b/cc1/error.c @@ -48,23 +48,26 @@ setsafe(uint8_t type) 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); }