summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorragge <ragge>2009-03-12 20:19:43 +0000
committerragge <ragge>2009-03-12 20:19:43 +0000
commitb0d65300b1f981bd9ee6cb6de0755b41b9cd23f6 (patch)
treeec5008e82a662fba49812f8748e4c72cbd54c048
parent0ae485bf28d5b29d63757a3480af74900ad43607 (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.c15
1 files 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;
}