[Pcre-svn] [780] code/trunk/src: More refactoring for ovecto…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [780] code/trunk/src: More refactoring for ovector addressing.
Revision: 780
          http://www.exim.org/viewvc/pcre2?view=rev&revision=780
Author:   ph10
Date:     2017-05-11 17:49:58 +0100 (Thu, 11 May 2017)
Log Message:
-----------
More refactoring for ovector addressing.


Modified Paths:
--------------
    code/trunk/src/pcre2_intmodedep.h
    code/trunk/src/pcre2_match.c
    code/trunk/src/pcre2_match_data.c


Modified: code/trunk/src/pcre2_intmodedep.h
===================================================================
--- code/trunk/src/pcre2_intmodedep.h    2017-05-11 16:28:54 UTC (rev 779)
+++ code/trunk/src/pcre2_intmodedep.h    2017-05-11 16:49:58 UTC (rev 780)
@@ -637,7 +637,11 @@
   uint16_t name_count;            /* Number of name entries in the table */
 } pcre2_real_code;


-/* The real match data structure. */
+/* The real match data structure. Define ovector large so that array bound
+checkers don't grumble. Memory for this structure is obtained by calling
+pcre2_match_data_create(), which sets the size as the offset of ovector plus
+pairs of elements for each capturing group. (See also the heapframe structure
+below.) */

 typedef struct pcre2_real_match_data {
   pcre2_memctl     memctl;
@@ -650,7 +654,7 @@
   uint16_t         matchedby;     /* Type of match (normal, JIT, DFA) */
   uint16_t         oveccount;     /* Number of pairs */
   int              rc;            /* The return code from the match */
-  PCRE2_SIZE       ovector[1];    /* The first field */
+  PCRE2_SIZE       ovector[10000];/* The first field */
 } pcre2_real_match_data;




Modified: code/trunk/src/pcre2_match.c
===================================================================
--- code/trunk/src/pcre2_match.c    2017-05-11 16:28:54 UTC (rev 779)
+++ code/trunk/src/pcre2_match.c    2017-05-11 16:49:58 UTC (rev 780)
@@ -182,16 +182,10 @@
 #define Foffset_top        F->offset_top
 #define Foccu              F->occu
 #define Fop                F->op
+#define Fovector           F->ovector
 #define Freturn_id         F->return_id


-/* We need a cast for this one because F->ovector is a vector of size 2, at the
-end of the backtrack frame, but when there are capturing parentheses the space
-allocated is bigger so we want to be able to address more elements. Without the
-case, -fsanitize=undefined grumbles at this. */

-#define Fovector           F->ovector
-
-
 #ifdef DEBUG_FRAMES_DISPLAY
 /*************************************************
 *      Display current frames and contents       *


Modified: code/trunk/src/pcre2_match_data.c
===================================================================
--- code/trunk/src/pcre2_match_data.c    2017-05-11 16:28:54 UTC (rev 779)
+++ code/trunk/src/pcre2_match_data.c    2017-05-11 16:49:58 UTC (rev 780)
@@ -59,7 +59,7 @@
 pcre2_match_data *yield;
 if (oveccount < 1) oveccount = 1;
 yield = PRIV(memctl_malloc)(
-  sizeof(pcre2_match_data) + 2*oveccount*sizeof(PCRE2_SIZE),
+  offsetof(pcre2_match_data, ovector) + 2*oveccount*sizeof(PCRE2_SIZE),
   (pcre2_memctl *)gcontext);
 if (yield == NULL) return NULL;
 yield->oveccount = oveccount;