Core: Fix crash when inspecting a savestate with a timestamp that causes localtime() to error out.

This commit is contained in:
Admiral H. Curtiss 2024-02-18 04:45:37 +01:00
parent 52410813f2
commit d3140e72c3
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
1 changed files with 5 additions and 2 deletions

View File

@ -29,6 +29,7 @@
#include "Common/IOFile.h" #include "Common/IOFile.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/Thread.h" #include "Common/Thread.h"
#include "Common/TimeUtil.h"
#include "Common/Timer.h" #include "Common/Timer.h"
#include "Common/Version.h" #include "Common/Version.h"
#include "Common/WorkQueueThread.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 // revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again
const time_t seconds = static_cast<time_t>(time) + DOUBLE_TIME_OFFSET; const time_t seconds = static_cast<time_t>(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. // 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); static std::string MakeStateFilename(int number);