dtracy: fix lexer bug

This commit is contained in:
aiju 2018-12-08 18:04:25 +00:00
parent 722a1a3334
commit b96be17376

View file

@ -7,7 +7,7 @@
#include "fns.h" #include "fns.h"
#include "y.tab.h" #include "y.tab.h"
char *str, *strp; char *str, *strp, *stre;
int lineno = 1; int lineno = 1;
int errors; int errors;
@ -60,6 +60,7 @@ void
lexstring(char *s) lexstring(char *s)
{ {
str = strp = s; str = strp = s;
stre = str + strlen(str);
} }
void void
@ -88,7 +89,10 @@ yyerror(char *msg)
static int static int
getch(void) getch(void)
{ {
if(*strp == 0) return -1; if(strp >= stre){
strp++;
return -1;
}
return *strp++; return *strp++;
} }
@ -96,8 +100,7 @@ static void
ungetch(void) ungetch(void)
{ {
assert(strp > str); assert(strp > str);
if(*strp != 0) strp--;
strp--;
} }
int int