bkabrda / rpms / grep

Forked from rpms/grep 6 years ago
Clone
a403fe6
diff --git a/src/grep.c b/src/grep.c
97a0815
index eac540a..9fabeb8 100644
a403fe6
--- a/src/grep.c
a403fe6
+++ b/src/grep.c
97a0815
@@ -1386,7 +1386,8 @@ grep (int fd, struct stat const *st)
97a0815
           has_nulls = true;
97a0815
           if (binary_files == WITHOUT_MATCH_BINARY_FILES)
97a0815
             return 0;
97a0815
-          done_on_match = out_quiet = true;
97a0815
+          if (!count_matches)
97a0815
+            done_on_match = out_quiet = true;
97a0815
           nul_zapper = eol;
97a0815
           skip_nuls = skip_empty_lines;
a403fe6
         }
97a0815
diff --git a/tests/Makefile.am b/tests/Makefile.am
97a0815
index 2ade5be..2079ae5 100644
97a0815
--- a/tests/Makefile.am
97a0815
+++ b/tests/Makefile.am
97a0815
@@ -106,6 +106,7 @@ TESTS =						\
97a0815
   pcre						\
97a0815
   pcre-abort					\
97a0815
   pcre-context					\
97a0815
+  pcre-count					\
97a0815
   pcre-infloop					\
97a0815
   pcre-invalid-utf8-input			\
97a0815
   pcre-jitstack					\
97a0815
diff --git a/tests/Makefile.in b/tests/Makefile.in
97a0815
index b5bd7b5..ee516da 100644
97a0815
--- a/tests/Makefile.in
97a0815
+++ b/tests/Makefile.in
97a0815
@@ -1442,6 +1442,7 @@ TESTS = \
97a0815
   pcre						\
97a0815
   pcre-abort					\
97a0815
   pcre-context					\
97a0815
+  pcre-count					\
97a0815
   pcre-infloop					\
97a0815
   pcre-invalid-utf8-input			\
97a0815
   pcre-jitstack					\
97a0815
@@ -2250,6 +2251,13 @@ pcre-context.log: pcre-context
97a0815
 	--log-file $$b.log --trs-file $$b.trs \
97a0815
 	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
97a0815
 	"$$tst" $(AM_TESTS_FD_REDIRECT)
97a0815
+pcre-count.log: pcre-count
97a0815
+	@p='pcre-count'; \
97a0815
+	b='pcre-count'; \
97a0815
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
97a0815
+	--log-file $$b.log --trs-file $$b.trs \
97a0815
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
97a0815
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
97a0815
 pcre-infloop.log: pcre-infloop
97a0815
 	@p='pcre-infloop'; \
97a0815
 	b='pcre-infloop'; \
97a0815
diff --git a/tests/pcre-count b/tests/pcre-count
97a0815
new file mode 100755
97a0815
index 0000000..78e1c7c
97a0815
--- /dev/null
97a0815
+++ b/tests/pcre-count
97a0815
@@ -0,0 +1,23 @@
97a0815
+#! /bin/sh
97a0815
+# grep -P / grep -Pc are inconsistent results
97a0815
+# This bug affected grep versions 2.21 through 2.22.
97a0815
+#
97a0815
+# Copyright (C) 2015 Free Software Foundation, Inc.
97a0815
+#
97a0815
+# Copying and distribution of this file, with or without modification,
97a0815
+# are permitted in any medium without royalty provided the copyright
97a0815
+# notice and this notice are preserved.
a403fe6
+
97a0815
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
97a0815
+require_pcre_
97a0815
+
97a0815
+fail=0
97a0815
+
97a0815
+printf 'a\n%032768d\nb\x0\n%032768d\na\n' 0 0 > in
97a0815
+
97a0815
+LC_ALL=C grep -P 'a' in | wc -l > exp
97a0815
+
97a0815
+LC_ALL=C grep -Pc 'a' in > out ||  fail=1
97a0815
+compare exp out || fail=1
97a0815
+
97a0815
+Exit $fail