Skip to content

Commit 6960914

Browse files
committed
Core/Logger: Use thread-safe localtime_r
1 parent 14ca0b7 commit 6960914

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/core/logger.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ void Logger::logv(LoggerLevel_t level, const char* msg, va_list va)
124124

125125
char timeStr[256];
126126
time_t t;
127-
struct tm *tm;
128127
t = time(NULL);
129-
tm = localtime(&t);
130-
strftime(timeStr, 256, "%Y/%m/%d %H:%M:%S", tm);
128+
129+
struct tm tm;
130+
localtime_r(&t, &tm);
131+
132+
strftime(timeStr, 256, "%Y/%m/%d %H:%M:%S", &tm);
131133

132134
printf("%s: %s: %s: %s%s\n", timeStr, levelStr.c_str(), m_name.c_str(), spaces.c_str(), buf);
133135
}

0 commit comments

Comments
 (0)