summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glib/gregex.c8
-rw-r--r--glib/tests/regex.c13
2 files changed, 19 insertions, 2 deletions
diff --git a/glib/gregex.c b/glib/gregex.c
index 5fc7b16bc..2a54929bf 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -476,8 +476,12 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
* Note that there can be more PCRE errors with the same GRegexError
* and that some PCRE errors are useless for us.
*/
+ gint original_errcode = *errcode;
- switch (*errcode)
+ *errcode = -1;
+ *errmsg = NULL;
+
+ switch (original_errcode)
{
case PCRE2_ERROR_END_BACKSLASH:
*errcode = G_REGEX_ERROR_STRAY_BACKSLASH;
@@ -725,7 +729,7 @@ translate_compile_error (gint *errcode, const gchar **errmsg)
break;
}
- g_assert (*errcode != 0);
+ g_assert (*errcode != -1);
g_assert (*errmsg != NULL);
}
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index 3355f64e5..9a1977b24 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2187,6 +2187,18 @@ pcre2_ge (guint64 major, guint64 minor)
return (pcre2_major > major) || (pcre2_major == major && pcre2_minor >= minor);
}
+static void
+test_compile_errors (void)
+{
+ GRegex *regex;
+ GError *error = NULL;
+
+ regex = g_regex_new ("\\o{999}", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
+ g_assert_null (regex);
+ g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE);
+ g_clear_error (&error);
+}
+
int
main (int argc, char *argv[])
{
@@ -2204,6 +2216,7 @@ main (int argc, char *argv[])
g_test_add_func ("/regex/multiline", test_multiline);
g_test_add_func ("/regex/explicit-crlf", test_explicit_crlf);
g_test_add_func ("/regex/max-lookbehind", test_max_lookbehind);
+ g_test_add_func ("/regex/compile-errors", test_compile_errors);
/* TEST_NEW(pattern, compile_opts, match_opts) */
G_GNUC_BEGIN_IGNORE_DEPRECATIONS