From 53fbc50fa5dd0ae712c202d7c7dfda62e39bc2c4 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 22 Jan 2024 19:59:38 +0100 Subject: Allow for only h// to take an empty pattern --- src/grab.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/grab.c b/src/grab.c index 7ba0189..8117648 100644 --- a/src/grab.c +++ b/src/grab.c @@ -57,6 +57,9 @@ struct matches { struct op { char c; regex_t pat; +#ifdef GRAB_DEBUG + bool alloced; +#endif }; struct ops { @@ -246,8 +249,10 @@ main(int argc, char **argv) # if GIT_GRAB free(entry); # endif - for (size_t i = 0; i < ops.len; i++) - regfree(&ops.buf[i].pat); + for (size_t i = 0; i < ops.len; i++) { + if (ops.buf[i].alloced) + regfree(&ops.buf[i].pat); + } free(ops.buf); #endif @@ -278,7 +283,19 @@ comppat(char *s) p = ++s; s = xstrchrnul(s, delim); - op.pat = mkregex(p, s - p); + if (s - p == 0) { + if (op.c != 'h') + diex("Empty regex given to ā€˜%cā€™", op.c); + op.pat = ops.buf[ops.len - 1].pat; +#ifdef GRAB_DEBUG + op.alloced = false; +#endif + } else { + op.pat = mkregex(p, s - p); +#ifdef GRAB_DEBUG + op.alloced = true; +#endif + } dapush(&ops, op); if (*s) -- cgit v1.2.3