• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 11521972f4d345d9a3f68df719f5980085197e47 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
3Date: Tue, 6 Sep 2022 18:26:12 +0200
4Subject: [PATCH] gregex: Handle the case we need to re-allocate the match data
5
6In case PCRE2 returns an empty match
7
8This can be easily tested by initializing the initial match data to a
9value that is less than the expected match values (e.g. by calling
10pcre2_match_data_create (1, NULL)), but we can't do it in our tests
11without bigger changes.
12---
13 glib/gregex.c | 15 ++++++++++++++-
14 1 file changed, 14 insertions(+), 1 deletion(-)
15
16diff --git a/glib/gregex.c b/glib/gregex.c
17index b886b24e2a..84c4245753 100644
18--- a/glib/gregex.c
19+++ b/glib/gregex.c
20@@ -1027,7 +1027,7 @@ g_match_info_next (GMatchInfo  *match_info,
21 {
22   gint prev_match_start;
23   gint prev_match_end;
24-  gint opts;
25+  uint32_t opts;
26
27   g_return_val_if_fail (match_info != NULL, FALSE);
28   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
29@@ -1075,6 +1075,19 @@ g_match_info_next (GMatchInfo  *match_info,
30                    match_info->regex->pattern, match_error (match_info->matches));
31       return FALSE;
32     }
33+  else if (match_info->matches == 0)
34+    {
35+      /* info->offsets is too small. */
36+      match_info->n_offsets *= 2;
37+      match_info->offsets = g_realloc_n (match_info->offsets,
38+                                         match_info->n_offsets,
39+                                         sizeof (gint));
40+
41+      pcre2_match_data_free (match_info->match_data);
42+      match_info->match_data = pcre2_match_data_create (match_info->n_offsets, NULL);
43+
44+      return g_match_info_next (match_info, error);
45+    }
46   else if (match_info->matches == PCRE2_ERROR_NOMATCH)
47     {
48       /* We're done with this match info */
49--
50GitLab
51
52