aboutsummaryrefslogtreecommitdiff
path: root/src/test/modules/test_regex/test_regex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/modules/test_regex/test_regex.c')
-rw-r--r--src/test/modules/test_regex/test_regex.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/modules/test_regex/test_regex.c b/src/test/modules/test_regex/test_regex.c
index ad3c6d3b1a6..095751cf04e 100644
--- a/src/test/modules/test_regex/test_regex.c
+++ b/src/test/modules/test_regex/test_regex.c
@@ -555,6 +555,18 @@ setup_test_matches(text *orig_str,
*/
if (matchctx->nmatches == 0 && re_flags->partial && re_flags->indices)
{
+ /* enlarge output space if needed */
+ while (array_idx + matchctx->npatterns * 2 + 1 > array_len)
+ {
+ array_len += array_len + 1; /* 2^n-1 => 2^(n+1)-1 */
+ if (array_len > MaxAllocSize / sizeof(int))
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("too many regular expression matches")));
+ matchctx->match_locs = (int *) repalloc(matchctx->match_locs,
+ sizeof(int) * array_len);
+ }
+
matchctx->match_locs[array_idx++] = matchctx->details.rm_extend.rm_so;
matchctx->match_locs[array_idx++] = matchctx->details.rm_extend.rm_eo;
/* we don't have pmatch data, so emit -1 */
@@ -566,6 +578,8 @@ setup_test_matches(text *orig_str,
matchctx->nmatches++;
}
+ Assert(array_idx <= array_len);
+
if (eml > 1)
{
int64 maxsiz = eml * (int64) maxlen;