[Pcre-svn] [650] code/trunk: Fix pcre2test mishandling "end …

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [650] code/trunk: Fix pcre2test mishandling "end before start" return with POSIX interface.
Revision: 650
          http://www.exim.org/viewvc/pcre2?view=rev&revision=650
Author:   ph10
Date:     2017-01-11 17:02:27 +0000 (Wed, 11 Jan 2017)
Log Message:
-----------
Fix pcre2test mishandling "end before start" return with POSIX interface.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2test.c
    code/trunk/testdata/testinput18
    code/trunk/testdata/testoutput18


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-01-11 16:40:35 UTC (rev 649)
+++ code/trunk/ChangeLog    2017-01-11 17:02:27 UTC (rev 650)
@@ -317,7 +317,11 @@
 XCLASS lists caused by characters with multiple other cases and pairs of
 characters in the same "not-x" sublists.


+49. A pattern such as /(?=(a\K))/ can report the end of the match being before
+its start; pcre2test was not handling this correctly when using the POSIX
+interface (it was OK with the native interface).

+
Version 10.22 29-July-2016
--------------------------


Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2017-01-11 16:40:35 UTC (rev 649)
+++ code/trunk/src/pcre2test.c    2017-01-11 17:02:27 UTC (rev 650)
@@ -6184,18 +6184,27 @@
       {
       if (pmatch[i].rm_so >= 0)
         {
+        PCRE2_SIZE start = pmatch[i].rm_so;
+        PCRE2_SIZE end = pmatch[i].rm_eo;
+        if (start > end)
+          {
+          start = pmatch[i].rm_eo;
+          end = pmatch[i].rm_so;
+          fprintf(outfile, "Start of matched string is beyond its end - "
+            "displaying from end to start.\n");
+          }
         fprintf(outfile, "%2d: ", (int)i);
-        PCHARSV(pp, pmatch[i].rm_so,
-          pmatch[i].rm_eo - pmatch[i].rm_so, utf, outfile);
+        PCHARSV(pp, start, end - start, utf, outfile);
         fprintf(outfile, "\n");
+
         if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
             (dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
           {
           fprintf(outfile, "%2d+ ", (int)i);
-          PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo,
-            utf, outfile);
-          fprintf(outfile, "\n");
-          }
+          /* Note: don't use the start/end variables here because we want to
+          show the text from what is reported as the end. */
+          PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
+          fprintf(outfile, "\n"); }
         }
       }
     }


Modified: code/trunk/testdata/testinput18
===================================================================
--- code/trunk/testdata/testinput18    2017-01-11 16:40:35 UTC (rev 649)
+++ code/trunk/testdata/testinput18    2017-01-11 17:02:27 UTC (rev 650)
@@ -106,4 +106,7 @@
 //posix_nosub
     \=offset=70000


+/(?=(a\K))/
+    a
+     
 # End of testdata/testinput18


Modified: code/trunk/testdata/testoutput18
===================================================================
--- code/trunk/testdata/testoutput18    2017-01-11 16:40:35 UTC (rev 649)
+++ code/trunk/testdata/testoutput18    2017-01-11 17:02:27 UTC (rev 650)
@@ -162,4 +162,10 @@
 ** Ignored with POSIX interface: offset
 Matched with REG_NOSUB


+/(?=(a\K))/
+    a
+Start of matched string is beyond its end - displaying from end to start.
+ 0: a
+ 1: a
+     
 # End of testdata/testinput18