summaryrefslogtreecommitdiff
path: root/dev-libs/libpcre/files/libpcre-8.40-pcregrep-multiline-1.patch
blob: f15968dfe98e0b0d4ac404186e5c71f8219f845c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From 5be027b624bc866702808abadfe5f99360414086 Mon Sep 17 00:00:00 2001
From: Philip Hazel <ph10@cam.ac.uk>
Date: Fri, 10 Feb 2017 17:47:34 +0000
Subject: [PATCH] Correct fix for pcre2grep multiline with --only-matching.

git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1678 2f5784b3-3f2a-0410-8824-cb99058d5e15
---
 ChangeLog    |  5 +++++
 configure.ac |  6 +++---
 pcregrep.c   | 20 +++++++++++++++-----
 3 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ab4e053e601e..373ee8422ef5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,11 @@ Version 8.41
 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
 ----------------------------
diff --git a/pcregrep.c b/pcregrep.c
index fd2a67622baa..2070c057e4a0 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,21 @@ 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;
+          }              
+
         goto ONLY_MATCHING_RESTART;
         }
       }
-- 
2.12.0