diff options
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r-- | src/backend/utils/adt/regexp.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index 1aebb39363f..39c5b889da1 100644 --- a/src/backend/utils/adt/regexp.c +++ b/src/backend/utils/adt/regexp.c @@ -936,6 +936,7 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, int array_len; int array_idx; int prev_match_end; + int prev_valid_match_end; int start_search; int maxlen = 0; /* largest fetch length in characters */ @@ -991,6 +992,7 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, /* search for the pattern, perhaps repeatedly */ prev_match_end = 0; + prev_valid_match_end = 0; start_search = 0; while (RE_wchar_execute(cpattern, wide_str, wide_len, start_search, pmatch_len, pmatch)) @@ -1043,13 +1045,15 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, matchctx->nmatches++; /* - * check length of unmatched portion between end of previous match - * and start of current one + * check length of unmatched portion between end of previous valid + * (nondegenerate, or degenerate but not ignored) match and start + * of current one */ if (fetching_unmatched && pmatch[0].rm_so >= 0 && - (pmatch[0].rm_so - prev_match_end) > maxlen) - maxlen = (pmatch[0].rm_so - prev_match_end); + (pmatch[0].rm_so - prev_valid_match_end) > maxlen) + maxlen = (pmatch[0].rm_so - prev_valid_match_end); + prev_valid_match_end = pmatch[0].rm_eo; } prev_match_end = pmatch[0].rm_eo; @@ -1075,8 +1079,8 @@ setup_regexp_matches(text *orig_str, text *pattern, text *flags, * input string */ if (fetching_unmatched && - (wide_len - prev_match_end) > maxlen) - maxlen = (wide_len - prev_match_end); + (wide_len - prev_valid_match_end) > maxlen) + maxlen = (wide_len - prev_valid_match_end); /* * Keep a note of the end position of the string for the benefit of |