An empty pattern matches every line, so combined with -v (invert) it can never select a line. GNU recognises this and short-circuits the whole run: it produces no output (so -c prints nothing, not 0) and never opens the input file, exiting 1. uu_grep runs normally — it prints the count 0, and reports an error / exits 2 for a missing file.
Found by the differential fuzzer (fuzz_grep). This is the same family as the -m 0 short-circuit (#4) but with a different trigger.
Rust (incorrect)
$ printf 'a\nb\n' | ./target/release/grep -e '' -v -c
# Output: 0
# Exit code: 1
GNU (correct)
$ printf 'a\nb\n' | LC_ALL=C /usr/bin/grep -e '' -v -c
# Output: (none)
# Exit code: 1
The short-circuit also skips opening files entirely — on a missing file GNU stays silent and exits 1, while uu_grep reports the open error and exits 2:
$ ./target/release/grep -e '' -v -c /nonexistent # grep: /nonexistent: No such file or directory (exit 2)
$ LC_ALL=C /usr/bin/grep -e '' -v -c /nonexistent # (no output, exit 1)
Controls that agree: grep -e '' -c (no -v) prints the line count in both; a normal zero-count case grep zzz -c prints 0 in both. The divergence is specific to the empty-pattern + -v combination, where the result set is provably empty.
An empty pattern matches every line, so combined with
-v(invert) it can never select a line. GNU recognises this and short-circuits the whole run: it produces no output (so-cprints nothing, not0) and never opens the input file, exiting1.uu_grepruns normally — it prints the count0, and reports an error / exits2for a missing file.Found by the differential fuzzer (
fuzz_grep). This is the same family as the-m 0short-circuit (#4) but with a different trigger.Rust (incorrect)
GNU (correct)
The short-circuit also skips opening files entirely — on a missing file GNU stays silent and exits 1, while
uu_grepreports the open error and exits 2:Controls that agree:
grep -e '' -c(no-v) prints the line count in both; a normal zero-count casegrep zzz -cprints0in both. The divergence is specific to the empty-pattern +-vcombination, where the result set is provably empty.