From 89b1f7ac955ae22c28f7916abc8adcd5f5db92fc Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 20 Mar 2015 14:32:26 -0400 Subject: [PATCH] fix strchr when buffer doesn't have an eol. if strchr(bp, '\n') didn't find anything the first time, it won't find anything the second time, either. Change to '\0' to find the end-of-line. It's still a syntax error (the grammar requires a '\n') but it won't cause an alloc error. --- lburg/gram.c | 2 +- lburg/gram.y | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lburg/gram.c b/lburg/gram.c index 0c867908..7c330e4a 100755 --- a/lburg/gram.c +++ b/lburg/gram.c @@ -316,7 +316,7 @@ int yylex(void) { bp += strspn(bp, " \t\f"); p = strchr(bp, '\n'); if (p == NULL) - p = strchr(bp, '\n'); + p = strchr(bp, '\0'); while (p > bp && isspace(p[-1])) p--; yylval.string = alloc(p - bp + 1); diff --git a/lburg/gram.y b/lburg/gram.y index 84d3ef31..33aed9d4 100755 --- a/lburg/gram.y +++ b/lburg/gram.y @@ -117,7 +117,7 @@ int yylex(void) { bp += strspn(bp, " \t\f"); p = strchr(bp, '\n'); if (p == NULL) - p = strchr(bp, '\n'); + p = strchr(bp, '\0'); while (p > bp && isspace(p[-1])) p--; yylval.string = alloc(p - bp + 1);