From 45c26241e646d51c2991dda0e3517c0c3aa29af2 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Mon, 20 Jan 2020 16:49:55 -0500 Subject: [PATCH] Fix race condition in LocalTimeDate() --- source/adios2/helper/adiosSystem.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/adios2/helper/adiosSystem.cpp b/source/adios2/helper/adiosSystem.cpp index 06ef1e423d..fab9d23e08 100644 --- a/source/adios2/helper/adiosSystem.cpp +++ b/source/adios2/helper/adiosSystem.cpp @@ -10,7 +10,9 @@ #include "adiosSystem.h" #include //system_clock, now #include +#include #include //std::cerr +#include #include // std::runtime_error, std::exception #include @@ -48,10 +50,20 @@ bool IsLittleEndian() noexcept std::string LocalTimeDate() noexcept { + struct tm now_tm; + std::ostringstream sout; + std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - return std::string(ctime(&now)); +#ifdef _WIN32 + localtime_s(&now_tm, &now); +#else + localtime_r(&now, &now_tm); +#endif + sout << std::put_time(&now_tm, "%a %b %d %H:%M:%S %Y\n"); + + return sout.str(); } bool IsRowMajor(const std::string hostLanguage) noexcept