Replaced non-thread-safe localtime with thread-safe equivalent localtime_r

This commit is contained in:
Thulinma 2018-05-19 21:02:40 +02:00
parent 3b16f03674
commit 3ce86d0e4c

View file

@ -21,7 +21,8 @@ static std::string strftime_now(const std::string& format) {
time_t rawtime; time_t rawtime;
char buffer[80]; char buffer[80];
time(&rawtime); time(&rawtime);
struct tm* timeinfo = localtime(&rawtime); struct tm timebuf;
struct tm* timeinfo = localtime_r(&rawtime, &timebuf);
if (!timeinfo || !strftime(buffer, 80, format.c_str(), timeinfo)){return "";} if (!timeinfo || !strftime(buffer, 80, format.c_str(), timeinfo)){return "";}
return buffer; return buffer;
} }