From d3140e72c3f59f203c6c85049c5bcd25f9b14f3b Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 18 Feb 2024 04:45:37 +0100 Subject: [PATCH] Core: Fix crash when inspecting a savestate with a timestamp that causes localtime() to error out. --- Source/Core/Core/State.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index e3e9a441c2..d60747deeb 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -29,6 +29,7 @@ #include "Common/IOFile.h" #include "Common/MsgHandler.h" #include "Common/Thread.h" +#include "Common/TimeUtil.h" #include "Common/Timer.h" #include "Common/Version.h" #include "Common/WorkQueueThread.h" @@ -282,10 +283,12 @@ static std::string SystemTimeAsDoubleToString(double time) { // revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again const time_t seconds = static_cast(time) + DOUBLE_TIME_OFFSET; - const tm local_time = fmt::localtime(seconds); + const auto local_time = Common::Localtime(seconds); + if (!local_time) + return ""; // fmt is locale agnostic by default, so explicitly use current locale. - return fmt::format(std::locale{""}, "{:%x %X}", local_time); + return fmt::format(std::locale{""}, "{:%x %X}", *local_time); } static std::string MakeStateFilename(int number);