Blob Blame History Raw
From dcee2708b5d37437fda9dbd07ccac6c9badd6892 Mon Sep 17 00:00:00 2001
From: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date: Fri, 10 Feb 2017 17:47:34 +0000
Subject: [PATCH] Correct fix for pcre2grep multiline with --only-matching.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is series of two patches ported to 8.40:

commit 5be027b624bc866702808abadfe5f99360414086
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date:   Fri Feb 10 17:47:34 2017 +0000

    Correct fix for pcre2grep multiline with --only-matching.

    git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1678 2f5784b3-3f2a-0410-8824-cb99058d5e15

commit 8b0fdf16e57ce9a653a0a03c39f6cc061e8122e8
Author: ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>
Date:   Sun Feb 12 13:28:11 2017 +0000

    Fix bug in most recent fix for multiline pcre2grep.

    git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1679 2f5784b3-3f2a-0410-8824-cb99058d5e15

Signed-off-by: Petr Písař <ppisar@redhat.com>
---
 pcregrep.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/pcregrep.c b/pcregrep.c
index fd2a676..3cd70ee 100644
--- a/pcregrep.c
+++ b/pcregrep.c
@@ -1804,11 +1804,6 @@ while (ptr < endptr)
         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,22 @@ while (ptr < endptr)
           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;
+          length = (size_t)(endptr - ptr); 
+          }              
+
         goto ONLY_MATCHING_RESTART;
         }
       }
-- 
2.7.4