Skip to content

Commit

Permalink
Fix race condition in LocalTimeDate()
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromKitware committed Feb 26, 2020
1 parent e0c14ca commit 45c2624
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion source/adios2/helper/adiosSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include "adiosSystem.h"
#include <chrono> //system_clock, now
#include <ctime>
#include <iomanip>
#include <iostream> //std::cerr
#include <sstream>
#include <stdexcept> // std::runtime_error, std::exception
#include <system_error>

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 45c2624

Please sign in to comment.