Blame grep-2.22-Pc-consistent-results.patch

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