diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-09-06 18:26:12 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2022-09-12 13:55:39 +0200 |
commit | 11521972f4d345d9a3f68df719f5980085197e47 (patch) | |
tree | f8aa2767c17f9c6cd58f3760e3ce9d46919cd3e3 /glib/gregex.c | |
parent | 1d628dac92283d75f7c751ddad72c28f4a7afe39 (diff) | |
download | glib-11521972f4d345d9a3f68df719f5980085197e47.tar.gz |
gregex: Handle the case we need to re-allocate the match data
In case PCRE2 returns an empty match
This can be easily tested by initializing the initial match data to a
value that is less than the expected match values (e.g. by calling
pcre2_match_data_create (1, NULL)), but we can't do it in our tests
without bigger changes.
Diffstat (limited to 'glib/gregex.c')
-rw-r--r-- | glib/gregex.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/glib/gregex.c b/glib/gregex.c index b886b24e2..84c424575 100644 --- a/glib/gregex.c +++ b/glib/gregex.c @@ -1027,7 +1027,7 @@ g_match_info_next (GMatchInfo *match_info, { gint prev_match_start; gint prev_match_end; - gint opts; + uint32_t opts; g_return_val_if_fail (match_info != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); @@ -1075,6 +1075,19 @@ g_match_info_next (GMatchInfo *match_info, match_info->regex->pattern, match_error (match_info->matches)); return FALSE; } + else if (match_info->matches == 0) + { + /* info->offsets is too small. */ + match_info->n_offsets *= 2; + match_info->offsets = g_realloc_n (match_info->offsets, + match_info->n_offsets, + sizeof (gint)); + + pcre2_match_data_free (match_info->match_data); + match_info->match_data = pcre2_match_data_create (match_info->n_offsets, NULL); + + return g_match_info_next (match_info, error); + } else if (match_info->matches == PCRE2_ERROR_NOMATCH) { /* We're done with this match info */ |