On 11/20/21 17:38, Duncan Roe wrote:

This was *documented* *behaviour*.

No, it wasn't documented whether the "Binary file matches" message is sent to stdout or to stderr. But now that you mention it, this should be documented. First patch attached, and installed into the development version.


I'd further suggest biaary matches output to stderr by the new option be not
affected by the setting of `-s`, only by `-I`. This reinstates orthogonality of
-s and -I which 271793f0 broke.

Hmm, you have a point that -s is documented to "Suppress error messages about nonexistent or unreadable files" and it's plausible to say that the "binary file matches" diagnostic, although it is about a binary file that 'grep' has some trouble reading, is not about a file that is "unreadable". So, let's fix the code to match that part of the spec again. Second patch attached and installed.

Since you have provided me with a workaround, I have no further interset in this
bug.

OK, closing the bug report. Thanks for reporting the issues.
From 56762bfda567ac2f96ab2f88e8117b5602bccddb Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 20 Nov 2021 22:51:26 -0800
Subject: [PATCH 1/2] doc: "binary file matches" -> stderr [Bug#51860]

---
 doc/grep.in.1 | 2 +-
 doc/grep.texi | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/grep.in.1 b/doc/grep.in.1
index 208cb76..123b8d6 100644
--- a/doc/grep.in.1
+++ b/doc/grep.in.1
@@ -520,7 +520,7 @@ and suppresses output lines that contain improperly encoded data.
 When some output is suppressed,
 .B grep
 follows any output
-with a one-line message saying that a binary file matches.
+with a message to standard error saying that a binary file matches.
 .IP
 If
 .I TYPE
diff --git a/doc/grep.texi b/doc/grep.texi
index c3c4bbf..b1da5cb 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -615,7 +615,7 @@ By default, @var{type} is @samp{binary}, and @command{grep}
 suppresses output after null input binary data is discovered,
 and suppresses output lines that contain improperly encoded data.
 When some output is suppressed, @command{grep} follows any output
-with a one-line message saying that a binary file matches.
+with a message to standard error saying that a binary file matches.
 
 If @var{type} is @samp{without-match},
 when @command{grep} discovers null input binary data
-- 
2.32.0

From af79b17356f2edeca2908c14d922a24f659d4a96 Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Sat, 20 Nov 2021 22:53:55 -0800
Subject: [PATCH 2/2] =?UTF-8?q?grep:=20-s=20does=20not=20suppress=20?=
 =?UTF-8?q?=E2=80=9Cbinary=20file=20matches=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/grep.c (grep): Implement this.
* tests/binary-file-matches: Add regression test.
---
 NEWS                      | 5 +++++
 src/grep.c                | 2 +-
 tests/binary-file-matches | 8 +++++---
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 2f63071..5015580 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,11 @@ GNU grep NEWS                                    -*- outline -*-
   release 2.5.3 (2007), now warn that they are obsolescent and should
   be replaced by grep -E and grep -F.
 
+** Bug fixes
+
+  The -s option no longer suppresses "binary file matches" messages.
+  [Bug#51860 introduced in grep 3.5]
+
 
 * Noteworthy changes in release 3.7 (2021-08-14) [stable]
 
diff --git a/src/grep.c b/src/grep.c
index a55194c..19dff43 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1646,7 +1646,7 @@ grep (int fd, struct stat const *st, bool *ineof)
  finish_grep:
   done_on_match = done_on_match_0;
   out_quiet = out_quiet_0;
-  if (binary_files == BINARY_BINARY_FILES && ! (out_quiet | suppress_errors)
+  if (binary_files == BINARY_BINARY_FILES && !out_quiet
       && (encoding_error_output
           || (0 <= nlines_first_null && nlines_first_null < nlines)))
     error (0, 0, _("%s: binary file matches"), input_filename ());
diff --git a/tests/binary-file-matches b/tests/binary-file-matches
index 7fc4a11..8fea071 100755
--- a/tests/binary-file-matches
+++ b/tests/binary-file-matches
@@ -14,8 +14,10 @@ fail=0
 echo "grep: (standard input): binary file matches" > exp \
   || framework_failure_
 
-printf 'a\0' | grep a > out 2> err || fail=1
-compare /dev/null out || fail=1
-compare exp err || fail=1
+for option in '' -s; do
+  printf 'a\0' | grep $option a > out 2> err || fail=1
+  compare /dev/null out || fail=1
+  compare exp err || fail=1
+done
 
 Exit $fail
-- 
2.32.0

Reply via email to