Skip to content

does not short-circuit an empty pattern with -v like GNU (same family as #4) #27

@sylvestre

Description

@sylvestre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions