[glib/wip/3v1n0/regex-pcre2-flags-fixes: 8/11] gregex: Handle the case we need to re-allocate the match data
- From: Marco Trevisan <marcotrevi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/3v1n0/regex-pcre2-flags-fixes: 8/11] gregex: Handle the case we need to re-allocate the match data
- Date: Tue, 6 Sep 2022 20:17:53 +0000 (UTC)
commit 0669465c08b50c7bf24963d8271bcff684778cb6
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Tue Sep 6 18:26:12 2022 +0200
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.
glib/gregex.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
---
diff --git a/glib/gregex.c b/glib/gregex.c
index 39fc570142..cbf96812e0 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -1084,6 +1084,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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]