diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-01-22 19:59:38 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-01-22 19:59:38 +0100 |
commit | 53fbc50fa5dd0ae712c202d7c7dfda62e39bc2c4 (patch) | |
tree | 5f61fc485a6cee58dec210265bf91e416c1a648b /src/grab.c | |
parent | af1e7e4f4a05e23f17cf06c4f1324487caea6aaf (diff) |
Allow for only h// to take an empty pattern
Diffstat (limited to 'src/grab.c')
-rw-r--r-- | src/grab.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -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) |