From 91bf60a31664db538ac28058e286268064b1e902 Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 13 Jan 2024 19:07:36 +0200 Subject: [PATCH] Check rv of localtime_r --- src/details/os.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/details/os.cpp b/src/details/os.cpp index b44864df..eafc60ce 100644 --- a/src/details/os.cpp +++ b/src/details/os.cpp @@ -84,14 +84,14 @@ spdlog::log_clock::time_point now() noexcept { #endif } std::tm localtime(const std::time_t &time_tt) noexcept { + std::tm* rv; + std::tm tm; #ifdef _WIN32 - std::tm tm; - ::localtime_s(&tm, &time_tt); + rv = ::localtime_s(&tm, &time_tt); #else - std::tm tm; - ::localtime_r(&time_tt, &tm); + rv = ::localtime_r(&time_tt, &tm); #endif - return tm; + return rv != nullptr ? tm : std::tm{}; } std::tm localtime() noexcept {