aboutsummaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-18 22:49:02 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-18 22:49:02 -0700
commit571b24e14566d6af359e89f53691c7d118761560 (patch)
treec57fdf457abc8e5b04d86d32e5073de7f6014b07 /vm.c
parent204185ac43f74160e20129e08af353563a40488e (diff)
Slightly better handling of NULL bytes
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/vm.c b/vm.c
index c57d6c3..2fb78be 100644
--- a/vm.c
+++ b/vm.c
@@ -83,7 +83,7 @@ static match_t *_match(grammar_t *g, file_t *f, const char *str, vm_op_t *op, un
{
switch (op->op) {
case VM_ANYCHAR: {
- if (!*str || (!op->multiline && *str == '\n'))
+ if (str >= f->end - 1 || (!op->multiline && *str == '\n'))
return NULL;
match_t *m = calloc(sizeof(match_t), 1);
m->op = op;
@@ -138,14 +138,14 @@ static match_t *_match(grammar_t *g, file_t *f, const char *str, vm_op_t *op, un
// This isn't in the for() structure because there needs to
// be at least once chance to match the pattern, even if
// we're at the end of the string already (e.g. "..$").
- if (*str && (op->multiline || *str != '\n')) ++str;
+ if (str < f->end && (op->multiline || *str != '\n')) ++str;
}
destroy_match(&m);
return NULL;
} else if (op->multiline) {
- while (*str) ++str;
+ str = f->end;
} else {
- while (*str && *str != '\n') ++str;
+ while (str < f->end && *str != '\n') ++str;
}
m->end = str;
return m;