From 5525b5e35121bdfd5eb566b7a08916fe90822422 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Wed, 29 Oct 2025 15:53:46 +1300 Subject: [PATCH 1/8] Fix Windows wctype.h usage for codepoints outside Unicode BMP. Windows' wchar_t is only 16 bits wide. As established by the towupper_l()/towlower_l() wrapper functions, we should avoid truncating overflowing code points when calling wctype.h functions, and just return false. Windows just can't answer that question, but it didn't make sense to return the answer for a totally different character. --- src/backend/utils/adt/pg_locale_libc.c | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/backend/utils/adt/pg_locale_libc.c b/src/backend/utils/adt/pg_locale_libc.c index 9c7fcd1fc7a..761ed1a0603 100644 --- a/src/backend/utils/adt/pg_locale_libc.c +++ b/src/backend/utils/adt/pg_locale_libc.c @@ -187,55 +187,64 @@ wc_isxdigit_libc_sb(pg_wchar wc, pg_locale_t locale) static bool wc_isdigit_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswdigit_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswdigit_l((wint_t) wc, locale->lt); } static bool wc_isalpha_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswalpha_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswalpha_l((wint_t) wc, locale->lt); } static bool wc_isalnum_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswalnum_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswalnum_l((wint_t) wc, locale->lt); } static bool wc_isupper_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswupper_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswupper_l((wint_t) wc, locale->lt); } static bool wc_islower_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswlower_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswlower_l((wint_t) wc, locale->lt); } static bool wc_isgraph_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswgraph_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswgraph_l((wint_t) wc, locale->lt); } static bool wc_isprint_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswprint_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswprint_l((wint_t) wc, locale->lt); } static bool wc_ispunct_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswpunct_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswpunct_l((wint_t) wc, locale->lt); } static bool wc_isspace_libc_mb(pg_wchar wc, pg_locale_t locale) { - return iswspace_l((wint_t) wc, locale->lt); + return (sizeof(wchar_t) >= 4 || wc <= 0xffff) && + iswspace_l((wint_t) wc, locale->lt); } static bool -- 2.50.1 (Apple Git-155)