diff --git a/src/grep.c b/src/grep.c index 192f9d1..f657607 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1487,6 +1487,8 @@ grepbuf (char *beg, char const *lim) break; if (!out_invert || p < b) { + if (list_files != LISTFILES_NONE) + return 1; char *prbeg = out_invert ? p : b; char *prend = out_invert ? b : endp; prtext (prbeg, prend); @@ -2899,7 +2901,7 @@ main (int argc, char **argv) if (max_count == INTMAX_MAX) done_on_match = true; } - out_quiet = count_matches | done_on_match; + out_quiet = count_matches | done_on_match | exit_on_match; if (out_after < 0) out_after = default_context; diff --git a/tests/max-count-overread b/tests/max-count-overread index f829cc5..e15ea77 100755 --- a/tests/max-count-overread +++ b/tests/max-count-overread @@ -18,4 +18,14 @@ printf 'x\nx\nx\n' >in || framework_failure (grep -m2 x >/dev/null && head -n1) out || fail=1 compare exp out || fail=1 +# The following two tests would fail before v3.11-70 +echo x > in || framework_failure_ +echo in > exp || framework_failure_ +grep -l -m1 . in > out || fail=1 +compare exp out || fail=1 + +# Ensure that this prints nothing and exits successfully. +grep -q -m1 . in > out || fail=1 +compare /dev/null out || fail=1 + Exit $fail