@@ -42,18 +42,23 @@ pcre_extra * extra;
42
42
re->m_extra = extra;
43
43
re->m_iExecutionError = 0 ; // no error now
44
44
45
+ // inspired by a suggestion by Twisol (to remove a hard-coded limit on the number of wildcards)
46
+ int capturecount = 0 ;
47
+ // how many captures did we get?
48
+ pcre_fullinfo (program, NULL , PCRE_INFO_CAPTURECOUNT, &capturecount);
49
+ // allocate memory for them
50
+ re->m_vOffsets .resize ((capturecount + 1 ) * 3 ); // add 1 for the whole expression
51
+
45
52
return re;
46
53
}
47
54
48
- #define MAX_PCRE_WILDCARDS 1000
49
-
50
55
int regexec (register t_regexp *prog,
51
56
register const char *string,
52
57
const int start_offset)
53
58
{
54
59
int options = App.m_bRegexpMatchEmpty ? 0 : PCRE_NOTEMPTY; // don't match on an empty string
55
60
int count;
56
- static int offsets [MAX_PCRE_WILDCARDS * 3 ]; // hopefully we won't recurse and crash ;)
61
+
57
62
58
63
LARGE_INTEGER start,
59
64
finish;
@@ -67,7 +72,7 @@ LARGE_INTEGER start,
67
72
68
73
pcre_callout = NULL ;
69
74
count = pcre_exec (prog->m_program , prog->m_extra , string, strlen (string),
70
- start_offset, options, offsets, NUMITEMS (offsets ));
75
+ start_offset, options, &prog-> m_vOffsets [ 0 ], prog-> m_vOffsets . size ( ));
71
76
72
77
if (App.m_iCounterFrequency )
73
78
{
@@ -83,6 +88,8 @@ LARGE_INTEGER start,
83
88
{
84
89
pcre_free (prog->m_program );
85
90
prog->m_program = NULL ;
91
+ pcre_free (prog->m_extra );
92
+ prog->m_extra = NULL ;
86
93
prog->m_iExecutionError = count; // remember reason
87
94
}
88
95
@@ -99,9 +106,6 @@ LARGE_INTEGER start,
99
106
100
107
prog->m_sTarget = string; // for extracting wildcards
101
108
prog->m_iCount = count; // ditto
102
- prog->m_vOffsets .clear ();
103
- // only need first 2/3 of offsets
104
- copy (offsets, &offsets [count * 2 ], back_inserter (prog->m_vOffsets ));
105
109
106
110
return true ; // match
107
111
}
0 commit comments