Skip to content

Commit

Permalink
Check std::localtime() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 14, 2024
1 parent 5870629 commit ff8f9d2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/app/stressTest.cpp
Expand Up @@ -189,7 +189,7 @@ std::string getDateTime()
// MSVC 2022 and MinGW-w64 compilers.
std::tm result;
std::time_t currentTime = std::time(nullptr);
if (localtime_r(&currentTime, &result) == nullptr)
if (!localtime_r(&currentTime, &result))
return "";

std::ostringstream oss;
Expand All @@ -204,6 +204,9 @@ std::string getDateTime()
#endif
std::time_t currentTime = std::time(nullptr);
std::tm* currentDateTime = std::localtime(&currentTime);
if (!currentDateTime)
return "";

std::ostringstream oss;
oss << std::put_time(currentDateTime, "[%b %d %H:%M] ");
return oss.str();
Expand Down

0 comments on commit ff8f9d2

Please sign in to comment.