From 7b233926e2a951a60945b8d83e5b8028fa8f2625 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 23 Aug 2022 00:07:59 -0400 Subject: [PATCH] libroot: Do not return LC_GLOBAL_LOCALE from __current_locale_t(). Not all things that accept locale_t can accept LC_GLOBAL_LOCALE, specifically nl_langinfo_l does not (the specification indicates that passing it is undefined behavior; indeed, no C library I glanced at seems to support that.) So, return a static locale_t pointing to the global values instead. Fixes #17875 and #17876. --- src/system/libroot/posix/locale/locale_t.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/system/libroot/posix/locale/locale_t.cpp b/src/system/libroot/posix/locale/locale_t.cpp index 2337a6a2e8..478150223d 100644 --- a/src/system/libroot/posix/locale/locale_t.cpp +++ b/src/system/libroot/posix/locale/locale_t.cpp @@ -266,7 +266,12 @@ extern "C" locale_t __current_locale_t() { locale_t locale = (locale_t)GetCurrentLocaleInfo(); - if (locale == NULL) - locale = LC_GLOBAL_LOCALE; + if (locale == NULL) { + static LocaleBackendData global_locale_t; + global_locale_t.backend = gGlobalLocaleBackend; + global_locale_t.databridge = &gGlobalLocaleDataBridge; + return (locale_t)&global_locale_t; + } + return locale; }