[Pcre-svn] [543] code/trunk: Avoid loop caused by (*SKIP) wi…

Página Inicial
Delete this message
Autor: Subversion repository
Data:  
Para: pcre-svn
Assunto: [Pcre-svn] [543] code/trunk: Avoid loop caused by (*SKIP) with an argument.
Revision: 543
          http://vcs.pcre.org/viewvc?view=rev&revision=543
Author:   ph10
Date:     2010-06-15 17:33:29 +0100 (Tue, 15 Jun 2010)


Log Message:
-----------
Avoid loop caused by (*SKIP) with an argument.

Modified Paths:
--------------
    code/trunk/pcre_exec.c
    code/trunk/testdata/testinput11
    code/trunk/testdata/testoutput11


Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2010-06-15 08:49:47 UTC (rev 542)
+++ code/trunk/pcre_exec.c    2010-06-15 16:33:29 UTC (rev 543)
@@ -6069,13 +6069,28 @@


   switch(rc)
     {
-    /* NOMATCH and PRUNE advance by one character. If MATCH_SKIP_ARG reaches
-    this level it means that a MARK that matched the SKIP's arg was not found.
-    We treat this as NOMATCH. THEN at this level acts exactly like PRUNE. */
+    /* SKIP passes back the next starting point explicitly, but if it is the 
+    same as the match we have just done, treat it as NOMATCH. */


+    case MATCH_SKIP:
+    if (md->start_match_ptr != start_match)
+      {  
+      new_start_match = md->start_match_ptr;
+      break;
+      }
+    /* Fall through */
+    
+    /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
+    the SKIP's arg was not found. We also treat this as NOMATCH. */
+     
+    case MATCH_SKIP_ARG:
+    /* Fall through */ 
+
+    /* NOMATCH and PRUNE advance by one character. THEN at this level acts
+    exactly like PRUNE. */
+
     case MATCH_NOMATCH:
     case MATCH_PRUNE:
-    case MATCH_SKIP_ARG:
     case MATCH_THEN:
     new_start_match = start_match + 1;
 #ifdef SUPPORT_UTF8
@@ -6085,12 +6100,6 @@
 #endif
     break;


-    /* SKIP passes back the next starting point explicitly. */
-
-    case MATCH_SKIP:
-    new_start_match = md->start_match_ptr;
-    break;
-
     /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */


     case MATCH_COMMIT:


Modified: code/trunk/testdata/testinput11
===================================================================
--- code/trunk/testdata/testinput11    2010-06-15 08:49:47 UTC (rev 542)
+++ code/trunk/testdata/testinput11    2010-06-15 16:33:29 UTC (rev 543)
@@ -435,6 +435,11 @@
 /A(*:A)A+(*SKIP:A)(B|Z) | AC/xK
     AAAC


+/--- Don't loop! ---/
+
+/(*:A)A+(*SKIP:A)(B|Z)/K
+    AAAC
+
 /--- This should succeed, as a non-existent skip name disables the skip ---/ 


/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/xK

Modified: code/trunk/testdata/testoutput11
===================================================================
--- code/trunk/testdata/testoutput11    2010-06-15 08:49:47 UTC (rev 542)
+++ code/trunk/testdata/testoutput11    2010-06-15 16:33:29 UTC (rev 543)
@@ -864,6 +864,12 @@
     AAAC
  0: AC


+/--- Don't loop! ---/
+
+/(*:A)A+(*SKIP:A)(B|Z)/K
+    AAAC
+No match, mark = A
+
 /--- This should succeed, as a non-existent skip name disables the skip ---/ 


/A(*MARK:A)A+(*SKIP:B)(B|Z) | AC/xK