Revision: 1586
http://vcs.pcre.org/viewvc?view=rev&revision=1586
Author: ph10
Date: 2015-08-05 18:43:19 +0100 (Wed, 05 Aug 2015)
Log Message:
-----------
Make pcregrep -q override -l and -c for compatibility with other greps.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/RunGrepTest
code/trunk/pcregrep.c
code/trunk/testdata/grepoutput
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2015-08-05 15:38:32 UTC (rev 1585)
+++ code/trunk/ChangeLog 2015-08-05 17:43:19 UTC (rev 1586)
@@ -106,6 +106,9 @@
reference to become recursive if a later named group with the relevant
number is encountered. This could lead to a buffer overflow. Wen Guanxing
from Venustech ADLAB discovered this bug.
+
+28. If pcregrep was given the -q option with -c or -l, or when handling a
+ binary file, it incorrectly wrote output to stdout.
Version 8.37 28-April-2015
Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest 2015-08-05 15:38:32 UTC (rev 1585)
+++ code/trunk/RunGrepTest 2015-08-05 17:43:19 UTC (rev 1586)
@@ -512,6 +512,14 @@
(cd $srcdir; $valgrind $pcregrep --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
echo "RC=$?" >>testtrygrep
+echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
+(cd $srcdir; $valgrind $pcregrep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
+echo "RC=$?" >>testtrygrep
+
+echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
+(cd $srcdir; $valgrind $pcregrep -cq lazy ./testdata/grepinput*) >>testtrygrep
+echo "RC=$?" >>testtrygrep
+
# Now compare the results.
$cf $srcdir/testdata/grepoutput testtrygrep
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2015-08-05 15:38:32 UTC (rev 1585)
+++ code/trunk/pcregrep.c 2015-08-05 17:43:19 UTC (rev 1586)
@@ -1692,9 +1692,13 @@
if (filenames == FN_NOMATCH_ONLY) return 1;
+ /* If all we want is a yes/no answer, stop now. */
+
+ if (quiet) return 0;
+
/* Just count if just counting is wanted. */
- if (count_only) count++;
+ else if (count_only) count++;
/* When handling a binary file and binary-files==binary, the "binary"
variable will be set true (it's false in all other cases). In this
@@ -1715,10 +1719,6 @@
return 0;
}
- /* Likewise, if all we want is a yes/no answer. */
-
- else if (quiet) return 0;
-
/* The --only-matching option prints just the substring that matched,
and/or one or more captured portions of it, as long as these strings are
not empty. The --file-offsets and --line-offsets options output offsets for
@@ -2089,7 +2089,7 @@
/* Print the match count if wanted */
-if (count_only)
+if (count_only && !quiet)
{
if (count > 0 || !omit_zero_count)
{
Modified: code/trunk/testdata/grepoutput
===================================================================
--- code/trunk/testdata/grepoutput 2015-08-05 15:38:32 UTC (rev 1585)
+++ code/trunk/testdata/grepoutput 2015-08-05 17:43:19 UTC (rev 1586)
@@ -751,3 +751,7 @@
2:3,1
2:4,1
RC=0
+---------------------------- Test 108 ------------------------------
+RC=0
+---------------------------- Test 109 -----------------------------
+RC=0