#3400: fix std::localtime not thread safe

This commit is contained in:
Günter Obiltschnig 2021-11-05 13:37:02 +01:00
parent fc0cc6af36
commit 5902bb1277

View File

@ -25,6 +25,8 @@
#include <ctime>
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
#include "wce_time.h"
#elif defined(_WIN32)
#include <time.h>
#endif
@ -269,7 +271,10 @@ void LocalDateTime::determineTzd(bool adjust)
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x800
std::tm* broken = wceex_localtime(&epochTime);
#else
std::tm* broken = std::localtime(&epochTime);
std::tm brokenBuf;
std::tm* broken = &brokenBuf;
errno_t err = localtime_s(broken, &epochTime);
if (err) broken = nullptr;
#endif
if (!broken) throw Poco::SystemException("cannot get local time");
_tzd = (Timezone::utcOffset() + ((broken->tm_isdst == 1) ? 3600 : 0));