From 94ba1fd177f28ef3d06f4aeb2e6044cb6c321992 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 14 Dec 2020 22:18:04 -0800 Subject: Fixes for nodent in nested matches --- vm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vm.c b/vm.c index 63c35e3..2486264 100644 --- a/vm.c +++ b/vm.c @@ -409,18 +409,19 @@ static match_t *_match(grammar_t *g, file_t *f, const char *str, vm_op_t *op, un size_t linenum = get_line_number(f, str); const char *p = get_line(f, linenum); + if (p < f->contents) p=f->contents; // Can happen with recursive matching // Current indentation: char denter = *p; int dents = 0; if (denter == ' ' || denter == '\t') { - for (; *p == denter; ++p) ++dents; + for (; *p == denter && p < f->end; ++p) ++dents; } // Subsequent indentation: while (*str == '\n') ++str; for (int i = 0; i < dents; i++) { - if (str[i] != denter) return NULL; + if (str[i] != denter || &str[i] >= f->end) return NULL; } match_t *m = calloc(sizeof(match_t), 1); -- cgit v1.2.3