aboutsummaryrefslogtreecommitdiff
path: root/src/grab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/grab.c')
-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)