grep-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep branch, master, updated. v2.22-32-g2982258


From: Paul Eggert
Subject: grep branch, master, updated. v2.22-32-g2982258
Date: Mon, 01 Feb 2016 07:29:50 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  2982258caee17e73e1d6d439efdc9f1eccd04e28 (commit)
      from  8b6a670569f1c99e63868c2a473490ddc5ec53a0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=2982258caee17e73e1d6d439efdc9f1eccd04e28


commit 2982258caee17e73e1d6d439efdc9f1eccd04e28
Author: Paul Eggert <address@hidden>
Date:   Sun Jan 31 23:29:01 2016 -0800

    Omit excess "Binary file ... matches"
    
    Problem reported in: http://bugs.gnu.org/22461
    * src/grep.c (grep): Don't report "Binary file ... matches"
    merely because the file contained both matches and binary data.
    Insist that the binary data contained a match.
    * tests/null-byte: Add a test for this.

diff --git a/src/grep.c b/src/grep.c
index 10aabf9..73c3651 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1373,7 +1373,11 @@ grep (int fd, struct stat const *st)
   char nul_zapper = '\0';
   bool done_on_match_0 = done_on_match;
   bool out_quiet_0 = out_quiet;
-  bool has_nulls = false;
+
+  /* The value of NLINES when nulls were first deduced in the input;
+     this is not necessarily the same as the number of matching lines
+     before the first null.  -1 if no input nulls have been deduced.  */
+  intmax_t nlines_first_null = -1;
 
   if (! reset (fd, st))
     return 0;
@@ -1400,15 +1404,15 @@ grep (int fd, struct stat const *st)
 
   for (bool firsttime = true; ; firsttime = false)
     {
-      if (!has_nulls && eol && binary_files != TEXT_BINARY_FILES
+      if (nlines_first_null < 0 && eol && binary_files != TEXT_BINARY_FILES
           && (buf_has_nulls (bufbeg, buflim - bufbeg)
               || (firsttime && file_must_have_nulls (buflim - bufbeg, fd, 
st))))
         {
-          has_nulls = true;
           if (binary_files == WITHOUT_MATCH_BINARY_FILES)
             return 0;
           if (!count_matches)
             done_on_match = out_quiet = true;
+          nlines_first_null = nlines;
           nul_zapper = eol;
           skip_nuls = skip_empty_lines;
         }
@@ -1445,7 +1449,8 @@ grep (int fd, struct stat const *st)
             nlines += grepbuf (beg, lim);
           if (pending)
             prpending (lim);
-          if ((!outleft && !pending) || (nlines && done_on_match))
+          if ((!outleft && !pending)
+              || (done_on_match && MAX (0, nlines_first_null) < nlines))
             goto finish_grep;
         }
 
@@ -1490,7 +1495,8 @@ grep (int fd, struct stat const *st)
  finish_grep:
   done_on_match = done_on_match_0;
   out_quiet = out_quiet_0;
-  if ((has_nulls || encoding_error_output) && !out_quiet && nlines != 0)
+  if (!out_quiet && (encoding_error_output
+                     || (0 <= nlines_first_null && nlines_first_null < 
nlines)))
     {
       printf (_("Binary file %s matches\n"), filename);
       if (line_buffered)
diff --git a/tests/null-byte b/tests/null-byte
index 44dad92..9a76887 100755
--- a/tests/null-byte
+++ b/tests/null-byte
@@ -51,4 +51,9 @@ for left in '' a '#' '\0'; do
   done
 done
 
+(echo xxx && yes yyy | sed 100000q && printf '\0') >in || framework_failure_
+echo xxx >exp || framework_failure_
+grep xxx in >out || fail=1
+compare exp out || fail=1
+
 Exit $fail

-----------------------------------------------------------------------

Summary of changes:
 src/grep.c      |   16 +++++++++++-----
 tests/null-byte |    5 +++++
 2 files changed, 16 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
grep



reply via email to

[Prev in Thread] Current Thread [Next in Thread]