aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-01-22 19:59:38 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-01-22 19:59:38 +0100
commit53fbc50fa5dd0ae712c202d7c7dfda62e39bc2c4 (patch)
tree5f61fc485a6cee58dec210265bf91e416c1a648b /src
parentaf1e7e4f4a05e23f17cf06c4f1324487caea6aaf (diff)
Allow for only h// to take an empty pattern
Diffstat (limited to 'src')
-rw-r--r--src/grab.c23
1 files changed, 20 insertions, 3 deletions
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)