From b0d65300b1f981bd9ee6cb6de0755b41b9cd23f6 Mon Sep 17 00:00:00 2001 From: ragge Date: Thu, 12 Mar 2009 20:19:43 +0000 Subject: Check if pushback buffer overflows. Tokens beginning with a digit may be an IDENT. Now seems to work as well as at least the old parser. --- token.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/token.c b/token.c index 9ba2aeb..91f0655 100644 --- a/token.c +++ b/token.c @@ -82,18 +82,22 @@ static int state; #define YYSTATE state char yytext[CPPBUF]; +static int owasnl, wasnl = 1; static void unch(int c) { - *--ifiles->curptr = c; + + --ifiles->curptr; + if (ifiles->curptr < ifiles->bbuf) + error("pushback buffer full"); + *ifiles->curptr = c; } int yylex() { - static int owasnl, wasnl = 1; int ch; int yyp; int os, mixed, haspmd; @@ -189,6 +193,9 @@ ppnum: for (;;) { unput(ch); yytext[yyp] = 0; + if (mixed == 1 && slow && (state == 0 || state == DEF)) + return IDENT; + if (mixed == 0) { if (slow && !YYSTATE) return IDENT; @@ -711,6 +718,7 @@ pushfile(usch *file) if ((c = yylex()) != 0) error("yylex returned %d", c); +wasnl = owasnl; if (otrulvl != trulvl || flslvl) error("unterminated conditional"); @@ -1134,7 +1142,8 @@ pragmastmt(void) if (!flslvl) putch(c); /* Do arg expansion instead? */ } while (c && c != '\n'); - ifiles->lineno++; + if (c == '\n') + unch(c); prtline(); slow = 0; } -- cgit v1.2.3