From 99a3bbc0552cfea13cd2928c67e53c7638b289ac Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" <pikachu025@gmail.com> Date: Mon, 30 Oct 2023 19:16:59 +0100 Subject: [PATCH] Core/State: Return an empty string on invalid input to SystemTimeAsDoubleToString(). --- Source/Core/Core/State.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 61b47a1198..eeb9b67924 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -265,16 +265,19 @@ static double GetSystemTimeAsDouble() static std::string SystemTimeAsDoubleToString(double time) { // revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again - time_t seconds = (time_t)time + DOUBLE_TIME_OFFSET; - tm* localTime = localtime(&seconds); + time_t seconds = static_cast<time_t>(time) + DOUBLE_TIME_OFFSET; + errno = 0; + tm* local_time = localtime(&seconds); + if (errno != 0 || !local_time) + return ""; #ifdef _WIN32 wchar_t tmp[32] = {}; - wcsftime(tmp, std::size(tmp), L"%x %X", localTime); + wcsftime(tmp, std::size(tmp), L"%x %X", local_time); return WStringToUTF8(tmp); #else char tmp[32] = {}; - strftime(tmp, sizeof(tmp), "%x %X", localTime); + strftime(tmp, sizeof(tmp), "%x %X", local_time); return tmp; #endif }