Skip to content

handles -q -c differently from GNU (prints the count 0 on no match instead of staying silent) #22

Closed

Description

@sylvestre

-q/--quiet must write nothing to stdout. When -q is combined with -c and the input contains no match, uu_grep still prints the count 0. GNU prints nothing. (When there is a match both stay silent, because -q makes the search exit early before the count is emitted — so the divergence only shows on the no-match path.)

Found by the differential fuzzer (fuzz_grep).

Rust (incorrect)

$ printf 'foo\n' | ./target/release/grep -e 'ZZZ' -q -c
# Output: 0
# Exit code: 1

GNU (correct)

$ printf 'foo\n' | LC_ALL=C /usr/bin/grep -e 'ZZZ' -q -c
# Output: (none)
# Exit code: 1

Controls that agree: -q -c with a match prints nothing in both; -q alone (no -c) prints nothing in both.

Activity

  1. sylvestre commented on Jun 4, 2026

    @sylvestre
    SponsorContributorAuthor

    The -L filename output leaks the same way on the no-match path (same quiet gap, different branch):

    $ printf 'foo\n' | ./target/release/grep -e ZZZ -q -L   # (standard input)
    $ printf 'foo\n' | LC_ALL=C /usr/bin/grep -e ZZZ -q -L   # (nothing)
  2. wondr-wclabs commented on Jun 5, 2026

    @wondr-wclabs
    Contributor

    I included the -L no-match case in #41 as part of the same fix. Both leaks come from EOF bookkeeping after the search reaches the end without a match: -c writes the final count and -L writes the filename. The patch puts the quiet-mode guard at the start of finalization so -q consistently means “exit status only,” whether the search exits early on a match or reaches EOF with no matches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions