[Pcre-svn] [472] code/trunk: Fix options set and reset at to…

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [472] code/trunk: Fix options set and reset at top level bug.
Revision: 472
          http://vcs.pcre.org/viewvc?view=rev&revision=472
Author:   ph10
Date:     2009-12-11 16:42:50 +0000 (Fri, 11 Dec 2009)


Log Message:
-----------
Fix options set and reset at top level bug.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_compile.c
    code/trunk/testdata/testinput1
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput1
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/ChangeLog    2009-12-11 16:42:50 UTC (rev 472)
@@ -8,6 +8,13 @@
     particular, this includes all (DEFINE) patterns), a call to pcre_study() 
     computed the wrong minimum data length (which is of course zero for such 
     subpatterns).
+    
+2.  For patterns such as (?i)a(?-i)b|c where an option setting at the start of 
+    the pattern is reset in the first branch, pcre_compile() failed with
+    "internal error: code overflow at offset...". This happened only when
+    the reset was to the original external option setting. (An optimization 
+    abstracts leading options settings into an external setting, which was the 
+    cause of this.)



Version 8.00 19-Oct-09

Modified: code/trunk/pcre_compile.c
===================================================================
--- code/trunk/pcre_compile.c    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/pcre_compile.c    2009-12-11 16:42:50 UTC (rev 472)
@@ -5248,7 +5248,7 @@
             {
             cd->external_options = newoptions;
             }
-         else
+          else
             {
             if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
               {
@@ -5783,6 +5783,7 @@
 int length;
 int orig_bracount;
 int max_bracount;
+int old_external_options = cd->external_options;
 branch_chain bc;


 bc.outer = bcptr;
@@ -5859,6 +5860,15 @@
     return FALSE;
     }


+  /* If the external options have changed during this branch, it means that we
+  are at the top level, and a leading option setting has been encountered. We
+  need to re-set the original option values to take account of this so that,
+  during the pre-compile phase, we know to allow for a re-set at the start of
+  subsequent branches. */
+
+  if (old_external_options != cd->external_options)
+    oldims = cd->external_options & PCRE_IMS;
+
   /* Keep the highest bracket count in case (?| was used and some branch
   has fewer than the rest. */


@@ -5969,7 +5979,7 @@
     PUT(code, 1, code - start_bracket);
     code += 1 + LINK_SIZE;


-    /* Resetting option if needed */
+    /* Reset options if needed. */


     if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
       {


Modified: code/trunk/testdata/testinput1
===================================================================
--- code/trunk/testdata/testinput1    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/testdata/testinput1    2009-12-11 16:42:50 UTC (rev 472)
@@ -4067,4 +4067,11 @@
 /^%((?(?=[a])[^%])|b)*%$/
     %ab%


+/(?i)a(?-i)b|c/
+    XabX
+    XAbX
+    CcC 
+    ** Failers
+    XABX   
+
 /-- End of testinput1 --/


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/testdata/testinput2    2009-12-11 16:42:50 UTC (rev 472)
@@ -3175,4 +3175,15 @@
 /()i(?(1)a)/SI 
     ia


+/(?i)a(?-i)b|c/BZ
+    XabX
+    XAbX
+    CcC 
+    ** Failers
+    XABX   
+
+/(?i)a(?s)b|c/BZ
+
+/(?i)a(?s-i)b|c/BZ
+
 /-- End of testinput2 --/


Modified: code/trunk/testdata/testoutput1
===================================================================
--- code/trunk/testdata/testoutput1    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/testdata/testoutput1    2009-12-11 16:42:50 UTC (rev 472)
@@ -6649,4 +6649,16 @@
  0: %ab%
  1: 


+/(?i)a(?-i)b|c/
+    XabX
+ 0: ab
+    XAbX
+ 0: Ab
+    CcC 
+ 0: c
+    ** Failers
+No match
+    XABX   
+No match
+
 /-- End of testinput1 --/


Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2009-12-11 15:11:55 UTC (rev 471)
+++ code/trunk/testdata/testoutput2    2009-12-11 16:42:50 UTC (rev 472)
@@ -10486,4 +10486,53 @@
  0: ia
  1: 


+/(?i)a(?-i)b|c/BZ
+------------------------------------------------------------------
+        Bra
+     NC a
+     00 Opt
+        b
+        Alt
+     00 Opt
+        c
+        Ket
+        End
+------------------------------------------------------------------
+    XabX
+ 0: ab
+    XAbX
+ 0: Ab
+    CcC 
+ 0: c
+    ** Failers
+No match
+    XABX   
+No match
+
+/(?i)a(?s)b|c/BZ
+------------------------------------------------------------------
+        Bra
+     NC a
+     05 Opt
+     NC b
+        Alt
+     05 Opt
+     NC c
+        Ket
+        End
+------------------------------------------------------------------
+
+/(?i)a(?s-i)b|c/BZ
+------------------------------------------------------------------
+        Bra
+     NC a
+     04 Opt
+        b
+        Alt
+     04 Opt
+        c
+        Ket
+        End
+------------------------------------------------------------------
+
 /-- End of testinput2 --/