diff --git a/libaegisub/common/util.cpp b/libaegisub/common/util.cpp index 117696e424..de23eeabc3 100644 --- a/libaegisub/common/util.cpp +++ b/libaegisub/common/util.cpp @@ -186,6 +186,13 @@ void InitLocale() { // FIXME: Should the ICU locale also be forced to en_US here? if (result != std::codecvt_base::ok) locale = boost::locale::generator().generate("en_US.UTF-8"); + + // Use the standard library's number parsing and formatting rather than + // Boost.Locale's, which nothing relies on. Boost.Locale's facets fall back + // to std::num_get code inlined from the SDK's libc++ headers, and with + // newer SDKs that code overflows a stack buffer when it calls into an + // older system libc++ (e.g. on macOS 13). + locale = std::locale(locale, std::locale::classic(), std::locale::numeric); std::locale::global(locale); } } // namespace util diff --git a/tests/tests/util.cpp b/tests/tests/util.cpp index 14757f8bbd..afb3632395 100644 --- a/tests/tests/util.cpp +++ b/tests/tests/util.cpp @@ -18,6 +18,9 @@ #include +#include +#include + class lagi_util : public libagi { }; namespace agi { @@ -42,4 +45,11 @@ TEST(lagi_util, try_parse_int) { EXPECT_EQ(1.0, i); } +TEST(lagi_util, init_locale_uses_std_numeric_facets) { + // Boost.Locale's numeric facets crash on older macOS when built with a + // newer SDK (#733), so InitLocale must not install them + EXPECT_EQ(typeid(std::num_get), typeid(std::use_facet>(std::locale()))); + EXPECT_EQ(typeid(std::num_put), typeid(std::use_facet>(std::locale()))); +} + }