From 16eee73dbf2e647363ddb9781684a3d859f2d65c 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source/adios2/helper/adiosSystem.cpp b/source/adios2/helper/adiosSystem.cpp index 06ef1e423d..c93a9a10bc 100644 --- a/source/adios2/helper/adiosSystem.cpp +++ b/source/adios2/helper/adiosSystem.cpp @@ -48,10 +48,20 @@ bool IsLittleEndian() noexcept std::string LocalTimeDate() noexcept { + struct tm now_tm; + char buf[30]; + 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 + strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y\n", &now_tm); + + return std::string(buf); } bool IsRowMajor(const std::string hostLanguage) noexcept