aboutsummaryrefslogtreecommitdiff
path: root/src/backend/regex/regc_pg_locale.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2024-09-05 12:10:08 -0700
committerJeff Davis <jdavis@postgresql.org>2024-09-05 12:10:08 -0700
commit7829f85a6285b3703a53ba5963a4df2e768014df (patch)
tree9a0f4c20c689106c1e6fadf7c03ac293630d1ad4 /src/backend/regex/regc_pg_locale.c
parentfadff3fc94598db1d87e4242821964fb2850e19e (diff)
downloadpostgresql-7829f85a6285b3703a53ba5963a4df2e768014df.tar.gz
postgresql-7829f85a6285b3703a53ba5963a4df2e768014df.zip
Be more careful with error paths in pg_set_regex_collation().
Set global variables after error paths so that they don't end up in an inconsistent state. The inconsistent state doesn't lead to an actual problem, because after an error, pg_set_regex_collation() will be called again before the globals are accessed. Change extracted from patch by Andreas Karlsson, though not discussed explicitly. Discussion: https://postgr.es/m/60929555-4709-40a7-b136-bcb44cff5a3c@proxel.se
Diffstat (limited to 'src/backend/regex/regc_pg_locale.c')
-rw-r--r--src/backend/regex/regc_pg_locale.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/backend/regex/regc_pg_locale.c b/src/backend/regex/regc_pg_locale.c
index 554a71e75a5..35361c46a60 100644
--- a/src/backend/regex/regc_pg_locale.c
+++ b/src/backend/regex/regc_pg_locale.c
@@ -231,6 +231,9 @@ static const unsigned char pg_char_properties[128] = {
void
pg_set_regex_collation(Oid collation)
{
+ pg_locale_t locale = 0;
+ PG_Locale_Strategy strategy;
+
if (!OidIsValid(collation))
{
/*
@@ -246,40 +249,41 @@ pg_set_regex_collation(Oid collation)
if (lc_ctype_is_c(collation))
{
/* C/POSIX collations use this path regardless of database encoding */
- pg_regex_strategy = PG_REGEX_STRATEGY_C;
- pg_regex_locale = 0;
- pg_regex_collation = C_COLLATION_OID;
+ strategy = PG_REGEX_STRATEGY_C;
+ collation = C_COLLATION_OID;
}
else
{
- pg_regex_locale = pg_newlocale_from_collation(collation);
+ locale = pg_newlocale_from_collation(collation);
- if (!pg_locale_deterministic(pg_regex_locale))
+ if (!pg_locale_deterministic(locale))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("nondeterministic collations are not supported for regular expressions")));
- if (pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
+ if (locale->provider == COLLPROVIDER_BUILTIN)
{
Assert(GetDatabaseEncoding() == PG_UTF8);
- pg_regex_strategy = PG_REGEX_STRATEGY_BUILTIN;
+ strategy = PG_REGEX_STRATEGY_BUILTIN;
}
#ifdef USE_ICU
- else if (pg_regex_locale->provider == COLLPROVIDER_ICU)
+ else if (locale->provider == COLLPROVIDER_ICU)
{
- pg_regex_strategy = PG_REGEX_STRATEGY_ICU;
+ strategy = PG_REGEX_STRATEGY_ICU;
}
#endif
else
{
if (GetDatabaseEncoding() == PG_UTF8)
- pg_regex_strategy = PG_REGEX_STRATEGY_LIBC_WIDE;
+ strategy = PG_REGEX_STRATEGY_LIBC_WIDE;
else
- pg_regex_strategy = PG_REGEX_STRATEGY_LIBC_1BYTE;
+ strategy = PG_REGEX_STRATEGY_LIBC_1BYTE;
}
-
- pg_regex_collation = collation;
}
+
+ pg_regex_strategy = strategy;
+ pg_regex_locale = locale;
+ pg_regex_collation = collation;
}
static int