shithub: riscv

Download patch

ref: b96be173766c58ccfcc3abc84bd751ba000be838
parent: 722a1a33347c759c797da9f889ceaed304092aff
author: aiju <devnull@localhost>
date: Sat Dec 8 13:04:25 EST 2018

dtracy: fix lexer bug

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