aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-04-26 13:52:01 -0500
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-04-26 13:52:01 -0500
commit87d6844bb00977089cd14d53dc8156a32de65eb7 (patch)
tree71e23049d00918ba3c5eb2cb04ee612a3f175bce
parent1d1765af605fb927021ad8f7e27bacb520bcfa85 (diff)
Fix: fall back to "C" locale when system lacks user's LANG
std::locale("") at static-init throws std::runtime_error on systems where the requested locale (e.g. en_US.UTF-8) isn't generated, killing Fluorine before main() runs. Wrap in try/catch and fall back to the classic locale. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
-rw-r--r--src/src/shared/util.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/src/shared/util.cpp b/src/src/shared/util.cpp
index ec720d2..71e735e 100644
--- a/src/src/shared/util.cpp
+++ b/src/src/shared/util.cpp
@@ -129,7 +129,19 @@ std::wstring ToWString(const std::string& source, bool utf8)
}
#endif
-static std::locale loc("");
+static std::locale makeUserLocale()
+{
+ // std::locale("") reads LANG/LC_* env vars. If user's system lacks the
+ // requested locale (e.g. en_US.UTF-8 not generated), constructor throws
+ // runtime_error. Fall back to "C" so startup doesn't abort.
+ try {
+ return std::locale("");
+ } catch (const std::runtime_error&) {
+ return std::locale::classic();
+ }
+}
+
+static std::locale loc = makeUserLocale();
static auto locToLowerW = [](wchar_t in) -> wchar_t {
return std::tolower(in, loc);
};