fix grep -m2 pattern bug
This commit is contained in:
parent
05f4302413
commit
8392fcf162
62
fix-grep-m2-pattern.patch
Normal file
62
fix-grep-m2-pattern.patch
Normal file
@ -0,0 +1,62 @@
|
||||
From b9a8047099d2388c15e6ad39e7b8c91c6633096c Mon Sep 17 00:00:00 2001
|
||||
From: Paul Eggert <eggert@cs.ucla.edu>
|
||||
Date: Fri, 9 Feb 2024 01:06:49 -0800
|
||||
Subject: =?UTF-8?q?grep:=20fix=20=E2=80=98grep=20-m2=20pattern=20<file=20>?=
|
||||
=?UTF-8?q?/dev/null=E2=80=99?=
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
|
||||
Problem reported by Grisha Levit <https://bugs.gnu.org/68989>.
|
||||
* src/grep.c (grep, main): Don’t set done_on_match if -m is used.
|
||||
* tests/max-count-overread: Add a test case.
|
||||
---
|
||||
src/grep.c | 9 +++++++--
|
||||
tests/max-count-overread | 6 ++++++
|
||||
2 files changed, 13 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/grep.c b/src/grep.c
|
||||
index dab3be7..1256dfd 100644
|
||||
--- a/src/grep.c
|
||||
+++ b/src/grep.c
|
||||
@@ -1558,7 +1558,11 @@ grep (int fd, struct stat const *st, bool *ineof)
|
||||
if (binary_files == WITHOUT_MATCH_BINARY_FILES)
|
||||
return 0;
|
||||
if (!count_matches)
|
||||
- done_on_match = out_quiet = true;
|
||||
+ {
|
||||
+ out_quiet = true;
|
||||
+ if (max_count == INTMAX_MAX)
|
||||
+ done_on_match = true;
|
||||
+ }
|
||||
nlines_first_null = nlines;
|
||||
nul_zapper = eol;
|
||||
skip_nuls = skip_empty_lines;
|
||||
@@ -2897,7 +2901,8 @@ main (int argc, char **argv)
|
||||
if ((exit_on_match | dev_null_output) || list_files != LISTFILES_NONE)
|
||||
{
|
||||
count_matches = false;
|
||||
- done_on_match = true;
|
||||
+ if (max_count == INTMAX_MAX)
|
||||
+ done_on_match = true;
|
||||
}
|
||||
out_quiet = count_matches | done_on_match;
|
||||
|
||||
diff --git a/tests/max-count-overread b/tests/max-count-overread
|
||||
index 23c45cb..f829cc5 100755
|
||||
--- a/tests/max-count-overread
|
||||
+++ b/tests/max-count-overread
|
||||
@@ -12,4 +12,10 @@ echo x > exp || framework_failure_
|
||||
yes x | timeout 10 grep -m1 x > out || fail=1
|
||||
compare exp out || fail=1
|
||||
|
||||
+# Make sure -m2 stops reading even when output is /dev/null.
|
||||
+# In grep 3.11, it would continue reading.
|
||||
+printf 'x\nx\nx\n' >in || framework_failure
|
||||
+(grep -m2 x >/dev/null && head -n1) <in >out || fail=1
|
||||
+compare exp out || fail=1
|
||||
+
|
||||
Exit $fail
|
||||
--
|
||||
cgit v1.1
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: grep
|
||||
Version: 3.11
|
||||
Release: 1
|
||||
Release: 2
|
||||
Summary: A string search utility
|
||||
License: GPLv3+
|
||||
URL: http://www.gnu.org/software/grep/
|
||||
@ -9,6 +9,8 @@ Source1: color_grep.sh
|
||||
Source2: colorgrep.csh
|
||||
Source3: grepconf.sh
|
||||
|
||||
Patch0001: fix-grep-m2-pattern.patch
|
||||
|
||||
BuildRequires: gcc pcre2-devel texinfo gettext libsigsegv-devel automake
|
||||
Provides: /bin/egrep /bin/fgrep /bin/grep bundled(gnulib)
|
||||
|
||||
@ -53,6 +55,9 @@ make check
|
||||
|
||||
|
||||
%changelog
|
||||
* Mon Jun 03 2024 wangziliang <wangziliang@kylinos.cn> - 3.11-2
|
||||
- fix grep -m2 pattern bug
|
||||
|
||||
* Fri Jul 14 2023 dillon chen <dillon.chen@gmail.com> - 3.11-1
|
||||
- update version to 3.11
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user