Use the more secure localtime_r variant

Pointed out by code scanning
This commit is contained in:
Kovid Goyal 2020-07-07 09:20:27 +05:30
parent 26699cd9ef
commit 17f34d1f95
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -31,7 +31,8 @@ log_error(const char *fmt, ...) {
#define bufprint(func, ...) { if ((size_t)(p - logbuf) < sizeof(logbuf) - 2) { p += func(p, sizeof(logbuf) - (p - logbuf), __VA_ARGS__); } }
if (!use_os_log) { // Apple's os_log already records timestamps
gettimeofday(&tv, NULL);
struct tm *tmp = localtime(&tv.tv_sec);
struct tm stack_tmp;
struct tm *tmp = localtime_r(&tv.tv_sec, &stack_tmp);
if (tmp) {
char tbuf[256] = {0}, buf[256] = {0};
if (strftime(buf, sizeof(buf), "%j %H:%M:%S.%%06u", tmp) != 0) {