With before-context (-B/-C), uu_grep prints a -- group separator between two output groups even when they are adjacent — i.e. the next group's context begins on the line immediately after the last line already printed. GNU only prints -- when there is a real gap (one or more skipped lines) between groups.
Found by the differential fuzzer (fuzz_grep).
Input is five lines: a, b, empty, empty, c. Pattern . matches the three non-empty lines.
Rust (incorrect)
$ printf 'a\nb\n\n\nc\n' | ./target/release/grep -e '.' -B 2
a
b
--
c
# Exit code: 0
GNU (correct)
$ printf 'a\nb\n\n\nc\n' | LC_ALL=C /usr/bin/grep -e '.' -B 2
a
b
c
# Exit code: 0
The first group ends at line 2 (b). The match on line 5 (c) pulls in before-context lines 3 and 4, so the second group starts at line 3 — immediately after line 2. The groups touch, so no separator belongs there: GNU merges them, uu_grep inserts --.
With before-context (
-B/-C),uu_grepprints a--group separator between two output groups even when they are adjacent — i.e. the next group's context begins on the line immediately after the last line already printed. GNU only prints--when there is a real gap (one or more skipped lines) between groups.Found by the differential fuzzer (
fuzz_grep).Input is five lines:
a,b, empty, empty,c. Pattern.matches the three non-empty lines.Rust (incorrect)
GNU (correct)
The first group ends at line 2 (
b). The match on line 5 (c) pulls in before-context lines 3 and 4, so the second group starts at line 3 — immediately after line 2. The groups touch, so no separator belongs there: GNU merges them,uu_grepinserts--.