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.
This commit is contained in:
Augustin Cavalier
2022-08-23 00:07:59 -04:00
parent 1ef08da5a0
commit 7b233926e2
+7 -2
View File
@@ -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;
}