From 26064831203b25c6df184d4023b888321c15cd52 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Tue, 7 Jul 2026 21:49:48 -0700 Subject: [PATCH 1/2] Revert "Utils: comment out my_strptime wrapper" This reverts commit 3afaee173d27cd1d11764d93e282aa59a7b36ca6. --- src/Utils.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index a5c7293..386a047 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -149,17 +149,14 @@ char* my_strptime(const char* s, const char* f, struct tm* tm) { - // just use normal strptime, the DIY implementation was being Weird - return strptime(s, f, tm); - - // std::istringstream input(s); - // input.imbue(std::locale(setlocale(LC_ALL, nullptr))); - // input >> std::get_time(tm, f); - // if (input.fail()) - // { - // return nullptr; - // } - // return (char*)(s + input.tellg()); + std::istringstream input(s); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, f); + if (input.fail()) + { + return nullptr; + } + return (char*)(s + input.tellg()); } // http://stackoverflow.com/a/11366985 From ce26c4435c36a81ce8d87f31c42e6614fc9a516b Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Tue, 7 Jul 2026 21:51:44 -0700 Subject: [PATCH 2/2] Fix date parsing crash on newer libc Since newlib commit e5a9f552ecf908f1639b08729edc191c66f4e7d0, setlocale(LC_ALL, null) returns "C/C.UTF-8/C/C/C/C" instead of "C". And libstdc++'s std::locale(char*) cannot parse that locale and throws a runtime_error, which corrupts the call stack resulting in a segfault. To fix this, pass std::locale::classic() directly and skip the setlocale business. And if even this fails, catch the exception and fail the function instead. Is it likely to throw an exception? Probably not. Ideally I'd exit the entire app cleanly (preferably avoiding a game/applet crash) rather than silently swallowing the exception, but I don't know how... --- src/Utils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 386a047..36186f0 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -148,15 +148,17 @@ int my_mkdir(const std::string& path, int perms) char* my_strptime(const char* s, const char* f, struct tm* tm) -{ +try { std::istringstream input(s); - input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input.imbue(std::locale::classic()); input >> std::get_time(tm, f); if (input.fail()) { return nullptr; } return (char*)(s + input.tellg()); +} catch (...) { + return nullptr; } // http://stackoverflow.com/a/11366985