Revision: 1678
http://vcs.pcre.org/viewvc?view=rev&revision=1678
Author: ph10
Date: 2017-02-10 17:47:34 +0000 (Fri, 10 Feb 2017)
Log Message:
-----------
Correct fix for pcre2grep multiline with --only-matching.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/configure.ac
code/trunk/pcregrep.c
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2017-01-23 16:35:09 UTC (rev 1677)
+++ code/trunk/ChangeLog 2017-02-10 17:47:34 UTC (rev 1678)
@@ -10,7 +10,12 @@
1. Fixed typo in CMakeLists.txt (wrong number of arguments for
PCRE_STATIC_RUNTIME (affects MSVC only).
+2. Issue 1 for 8.40 below was not correctly fixed. If pcregrep in multiline
+mode with --only-matching matched several lines, it restarted scanning at the
+next line instead of moving on to the end of the matched string, which can be
+several lines after the start.
+
Version 8.40 11-January-2017
----------------------------
Modified: code/trunk/configure.ac
===================================================================
--- code/trunk/configure.ac 2017-01-23 16:35:09 UTC (rev 1677)
+++ code/trunk/configure.ac 2017-02-10 17:47:34 UTC (rev 1678)
@@ -9,9 +9,9 @@
dnl be defined as -RC2, for example. For real releases, it should be empty.
m4_define(pcre_major, [8])
-m4_define(pcre_minor, [40])
-m4_define(pcre_prerelease, [])
-m4_define(pcre_date, [2017-01-11])
+m4_define(pcre_minor, [41])
+m4_define(pcre_prerelease, [-RC1])
+m4_define(pcre_date, [2017-02-01])
# NOTE: The CMakeLists.txt file searches for the above variables in the first
# 50 lines of this file. Please update that if the variables above are moved.
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2017-01-23 16:35:09 UTC (rev 1677)
+++ code/trunk/pcregrep.c 2017-02-10 17:47:34 UTC (rev 1678)
@@ -1804,11 +1804,6 @@
if (line_buffered) fflush(stdout);
rc = 0; /* Had some success */
- /* If the current match ended past the end of the line (only possible
- in multiline mode), we are done with this line. */
-
- if ((unsigned int)offsets[1] > linelength) goto END_ONE_MATCH;
-
startoffset = offsets[1]; /* Restart after the match */
if (startoffset <= oldstartoffset)
{
@@ -1818,6 +1813,21 @@
if (utf8)
while ((matchptr[startoffset] & 0xc0) == 0x80) startoffset++;
}
+
+ /* If the current match ended past the end of the line (only possible
+ in multiline mode), we must move on to the line in which it did end
+ before searching for more matches. */
+
+ while (startoffset > (int)linelength)
+ {
+ matchptr = ptr += linelength + endlinelength;
+ filepos += (int)(linelength + endlinelength);
+ linenumber++;
+ startoffset -= (int)(linelength + endlinelength);
+ t = end_of_line(ptr, endptr, &endlinelength);
+ linelength = t - ptr - endlinelength;
+ }
+
goto ONLY_MATCHING_RESTART;
}
}