From 477540760a84bab3ae08c9ffc3be065d09daf239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 27 Jan 2021 11:49:52 +0100 Subject: [PATCH] Use gmtime_r instead of gmtime when compiling for posixy platforms --- src/catch2/reporters/catch_reporter_junit.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index eb4609663f..cff5d7d7ca 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -22,28 +22,22 @@ namespace Catch { namespace { std::string getCurrentTimestamp() { - // Beware, this is not reentrant because of backward compatibility issues - // Also, UTC only, again because of backward compatibility (%z is C++11) time_t rawtime; std::time(&rawtime); - auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); -#ifdef _MSC_VER std::tm timeInfo = {}; +#ifdef _MSC_VER gmtime_s(&timeInfo, &rawtime); #else - std::tm* timeInfo; - timeInfo = std::gmtime(&rawtime); + gmtime_r(&rawtime, &timeInfo); #endif + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); char timeStamp[timeStampSize]; const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; -#ifdef _MSC_VER std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); -#else - std::strftime(timeStamp, timeStampSize, fmt, timeInfo); -#endif + return std::string(timeStamp); }