[Pcre-svn] [1160] code/trunk: Fix bug introduced in commit 1…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1160] code/trunk: Fix bug introduced in commit 1133.
Revision: 1160
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1160
Author:   ph10
Date:     2019-08-26 17:28:26 +0100 (Mon, 26 Aug 2019)
Log Message:
-----------
Fix bug introduced in commit 1133. Lookbehinds that follow a condition were not 
always properly handled.


Modified Paths:
--------------
    code/trunk/src/pcre2_compile.c
    code/trunk/testdata/testinput1
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput1
    code/trunk/testdata/testoutput2


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2019-08-26 15:10:31 UTC (rev 1159)
+++ code/trunk/src/pcre2_compile.c    2019-08-26 16:28:26 UTC (rev 1160)
@@ -9465,7 +9465,7 @@
 Arguments
   pptr      points to where to start (start of pattern or start of lookahead)
   retptr    if not NULL, return the ket pointer here
-  recurses  chain of recurse_check to catch mutual recursion 
+  recurses  chain of recurse_check to catch mutual recursion
   cb        points to the compile block


 Returns:    0 on success, or an errorcode (cb->erroroffset will be set)
@@ -9472,7 +9472,7 @@
 */


 static int
-check_lookbehinds(uint32_t *pptr, uint32_t **retptr, 
+check_lookbehinds(uint32_t *pptr, uint32_t **retptr,
   parsed_recurse_check *recurses, compile_block *cb)
 {
 int max;
@@ -9549,15 +9549,24 @@
     break;


     case META_BACKREF_BYNAME:
+    case META_RECURSE_BYNAME:
+    pptr += 1 + SIZEOFFSET;
+    break;
+
     case META_COND_DEFINE:
     case META_COND_NAME:
     case META_COND_NUMBER:
     case META_COND_RNAME:
     case META_COND_RNUMBER:
-    case META_RECURSE_BYNAME:
     pptr += 1 + SIZEOFFSET;
+    nestlevel++;
     break;


+    case META_COND_VERSION:
+    pptr += 3;
+    nestlevel++;
+    break;
+
     case META_CALLOUT_STRING:
     pptr += 3 + SIZEOFFSET;
     break;
@@ -9576,7 +9585,6 @@
     break;


     case META_CALLOUT_NUMBER:
-    case META_COND_VERSION:
     pptr += 3;
     break;


@@ -9591,7 +9599,7 @@
     case META_LOOKBEHIND:
     case META_LOOKBEHINDNOT:
     case META_LOOKBEHIND_NA:
-    if (!set_lookbehind_lengths(&pptr, &max, &errorcode, &loopcount, 
+    if (!set_lookbehind_lengths(&pptr, &max, &errorcode, &loopcount,
          recurses, cb))
       return errorcode;
     break;
@@ -10421,12 +10429,12 @@
     errorcode = ERR31;
     goto HAD_CB_ERROR;
     }
-    
-  /* If study() set a bitmap of starting code units, it implies a minimum 
+
+  /* If study() set a bitmap of starting code units, it implies a minimum
   length of at least one. */
-    
+
   if ((re->flags & PCRE2_FIRSTMAPSET) != 0 && minminlength == 0)
-    minminlength = 1; 
+    minminlength = 1;


/* If the minimum length set (or not set) by study() is less than the minimum
implied by required code units, override it. */

Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2019-08-26 15:10:31 UTC (rev 1159)
+++ code/trunk/testdata/testinput1    2019-08-26 16:28:26 UTC (rev 1160)
@@ -6383,4 +6383,7 @@
 /(?<=(?=(?<=a)))b/
     ab


+/^(?<A>a)(?(<A>)b)((?<=b).*)$/
+    abc
+
 # End of testinput1 


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2019-08-26 15:10:31 UTC (rev 1159)
+++ code/trunk/testdata/testinput2    2019-08-26 16:28:26 UTC (rev 1160)
@@ -5748,4 +5748,14 @@
 /\A\s*((?:[^`]{28500}){4}|a)/I
     a


+/(?<A>a)(?(<A>)b)((?<=b).*)/B
+
+/(?(1)b)((?<=b).*)/B
+
+/(?(R1)b)((?<=b).*)/B
+
+/(?(DEFINE)b)((?<=b).*)/B
+
+/(?(VERSION=10.4)b)((?<=b).*)/B
+
# End of testinput2

Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2019-08-26 15:10:31 UTC (rev 1159)
+++ code/trunk/testdata/testoutput1    2019-08-26 16:28:26 UTC (rev 1160)
@@ -10106,4 +10106,10 @@
     ab
  0: b


+/^(?<A>a)(?(<A>)b)((?<=b).*)$/
+    abc
+ 0: abc
+ 1: a
+ 2: c
+
 # End of testinput1 


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2019-08-26 15:10:31 UTC (rev 1159)
+++ code/trunk/testdata/testoutput2    2019-08-26 16:28:26 UTC (rev 1160)
@@ -17294,6 +17294,99 @@
  0: a
  1: a


+/(?<A>a)(?(<A>)b)((?<=b).*)/B
+------------------------------------------------------------------
+        Bra
+        CBra 1
+        a
+        Ket
+        Cond
+      1 Cond ref
+        b
+        Ket
+        CBra 2
+        Assert back
+        Reverse
+        b
+        Ket
+        Any*+
+        Ket
+        Ket
+        End
+------------------------------------------------------------------
+
+/(?(1)b)((?<=b).*)/B
+------------------------------------------------------------------
+        Bra
+        Cond
+      1 Cond ref
+        b
+        Ket
+        CBra 1
+        Assert back
+        Reverse
+        b
+        Ket
+        Any*+
+        Ket
+        Ket
+        End
+------------------------------------------------------------------
+
+/(?(R1)b)((?<=b).*)/B
+------------------------------------------------------------------
+        Bra
+        Cond
+        Cond recurse 1
+        b
+        Ket
+        CBra 1
+        Assert back
+        Reverse
+        b
+        Ket
+        Any*+
+        Ket
+        Ket
+        End
+------------------------------------------------------------------
+
+/(?(DEFINE)b)((?<=b).*)/B
+------------------------------------------------------------------
+        Bra
+        Cond
+        Cond false
+        b
+        Ket
+        CBra 1
+        Assert back
+        Reverse
+        b
+        Ket
+        Any*+
+        Ket
+        Ket
+        End
+------------------------------------------------------------------
+
+/(?(VERSION=10.4)b)((?<=b).*)/B
+------------------------------------------------------------------
+        Bra
+        Cond
+        Cond false
+        b
+        Ket
+        CBra 1
+        Assert back
+        Reverse
+        b
+        Ket
+        Any*+
+        Ket
+        Ket
+        End
+------------------------------------------------------------------
+
 # End of testinput2
 Error -70: PCRE2_ERROR_BADDATA (unknown error number)
 Error -62: bad serialized data