From eff8d1823579880ac8d88459d37384beb61d7f46 Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Mon, 12 Apr 2021 11:32:31 +0900 Subject: [PATCH] Use localtime_r instead of localtime Change-Id: I808747c6f88c42b2794a08bbcc2d0c0abf653eaa Signed-off-by: Cheoleun Moon --- tests/vine-test/vine-multi-thread-test.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tests/vine-test/vine-multi-thread-test.cpp b/tests/vine-test/vine-multi-thread-test.cpp index 1189d46..86de01a 100644 --- a/tests/vine-test/vine-multi-thread-test.cpp +++ b/tests/vine-test/vine-multi-thread-test.cpp @@ -159,16 +159,19 @@ static void __get_current_time(char *buf) { int hour, min, sec, day, month; time_t now; - struct tm *local; + struct tm local; time(&now); - local = localtime(&now); + if (localtime_r(&now, &local) == NULL) { + __print_error("localtime_r() fails"); + return; + } - hour = local->tm_hour; - min = local->tm_min; - sec = local->tm_sec; - day = local->tm_mday; - month = local->tm_mon + 1; + hour = local.tm_hour; + min = local.tm_min; + sec = local.tm_sec; + day = local.tm_mday; + month = local.tm_mon + 1; snprintf(buf, VINE_LOGGER_TIME_MESSAGE_LEN, "[%02u-%02u %02u:%02u:%02u]", month, day, hour, min, sec); -- 2.7.4