diff options
author | ragge <ragge> | 2009-03-12 20:19:43 +0000 |
---|---|---|
committer | ragge <ragge> | 2009-03-12 20:19:43 +0000 |
commit | b0d65300b1f981bd9ee6cb6de0755b41b9cd23f6 (patch) | |
tree | ec5008e82a662fba49812f8748e4c72cbd54c048 | |
parent | 0ae485bf28d5b29d63757a3480af74900ad43607 (diff) |
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.
-rw-r--r-- | token.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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; } |