summaryrefslogtreecommitdiff
path: root/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'grep.c')
-rw-r--r--grep.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/grep.c b/grep.c
index 701e58de04..4e155ee9e6 100644
--- a/grep.c
+++ b/grep.c
@@ -1,3 +1,5 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "git-compat-util.h"
#include "config.h"
#include "gettext.h"
@@ -756,6 +758,7 @@ static struct grep_expr *grep_splice_or(struct grep_expr *x, struct grep_expr *y
assert(x->node == GREP_NODE_OR);
if (x->u.binary.right &&
x->u.binary.right->node == GREP_NODE_TRUE) {
+ free(x->u.binary.right);
x->u.binary.right = y;
break;
}
@@ -906,15 +909,17 @@ static int patmatch(struct grep_pat *p,
const char *line, const char *eol,
regmatch_t *match, int eflags)
{
- int hit;
-
if (p->pcre2_pattern)
- hit = !pcre2match(p, line, eol, match, eflags);
- else
- hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,
- eflags);
+ return !pcre2match(p, line, eol, match, eflags);
- return hit;
+ switch (regexec_buf(&p->regexp, line, eol - line, 1, match, eflags)) {
+ case 0:
+ return 1;
+ case REG_NOMATCH:
+ return 0;
+ default:
+ return -1;
+ }
}
static void strip_timestamp(const char *bol, const char **eol_p)
@@ -952,6 +957,8 @@ static int headerless_match_one_pattern(struct grep_pat *p,
again:
hit = patmatch(p, bol, eol, pmatch, eflags);
+ if (hit < 0)
+ hit = 0;
if (hit && p->word_regexp) {
if ((pmatch[0].rm_so < 0) ||
@@ -1461,6 +1468,8 @@ static int look_ahead(struct grep_opt *opt,
regmatch_t m;
hit = patmatch(p, bol, bol + *left_p, &m, 0);
+ if (hit < 0)
+ return -1;
if (!hit || m.rm_so < 0 || m.rm_eo < 0)
continue;
if (earliest < 0 || m.rm_so < earliest)
@@ -1655,9 +1664,13 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
if (try_lookahead
&& !(last_hit
&& (show_function ||
- lno <= last_hit + opt->post_context))
- && look_ahead(opt, &left, &lno, &bol))
- break;
+ lno <= last_hit + opt->post_context))) {
+ hit = look_ahead(opt, &left, &lno, &bol);
+ if (hit < 0)
+ try_lookahead = 0;
+ else if (hit)
+ break;
+ }
eol = end_of_line(bol, &left);
if ((ctx == GREP_CONTEXT_HEAD) && (eol == bol))