@@ -255,13 +255,12 @@ static int timestamp_print(const struct log_output *output,
255255 if (IS_ENABLED (CONFIG_LOG_BACKEND_NET ) && flags & LOG_OUTPUT_FLAG_FORMAT_SYSLOG ) {
256256#if defined(CONFIG_REQUIRES_FULL_LIBC )
257257 char time_str [sizeof ("1970-01-01T00:00:00" )];
258- struct tm * tm ;
259- time_t time ;
258+ struct tm tm_timestamp = { 0 } ;
259+ time_t time_seconds = total_seconds ;
260260
261- time = total_seconds ;
262- tm = gmtime (& time );
261+ gmtime_r (& time_seconds , & tm_timestamp );
263262
264- strftime (time_str , sizeof (time_str ), "%FT%T" , tm );
263+ strftime (time_str , sizeof (time_str ), "%FT%T" , & tm_timestamp );
265264
266265 length = print_formatted (output , "%s.%06uZ " ,
267266 time_str , ms * 1000U + us );
@@ -289,12 +288,12 @@ static int timestamp_print(const struct log_output *output,
289288 } else if (IS_ENABLED (CONFIG_LOG_OUTPUT_FORMAT_DATE_TIMESTAMP )) {
290289#if defined(CONFIG_REQUIRES_FULL_LIBC )
291290 char time_str [sizeof ("1970-01-01 00:00:00" )];
292- struct tm * tm_timestamp ;
291+ struct tm tm_timestamp = { 0 } ;
293292 time_t time_seconds = total_seconds ;
294293
295- tm_timestamp = gmtime (& time_seconds );
294+ gmtime_r (& time_seconds , & tm_timestamp );
296295
297- strftime (time_str , sizeof (time_str ), "%F %T" , tm_timestamp );
296+ strftime (time_str , sizeof (time_str ), "%F %T" , & tm_timestamp );
298297
299298 length = print_formatted (output , "[%s.%03u,%03u] " , time_str , ms ,
300299 us );
@@ -311,12 +310,12 @@ static int timestamp_print(const struct log_output *output,
311310 } else if (IS_ENABLED (CONFIG_LOG_OUTPUT_FORMAT_ISO8601_TIMESTAMP )) {
312311#if defined(CONFIG_REQUIRES_FULL_LIBC )
313312 char time_str [sizeof ("1970-01-01T00:00:00" )];
314- struct tm * tm_timestamp ;
313+ struct tm tm_timestamp = { 0 } ;
315314 time_t time_seconds = total_seconds ;
316315
317- tm_timestamp = gmtime (& time_seconds );
316+ gmtime_r (& time_seconds , & tm_timestamp );
318317
319- strftime (time_str , sizeof (time_str ), "%FT%T" , tm_timestamp );
318+ strftime (time_str , sizeof (time_str ), "%FT%T" , & tm_timestamp );
320319
321320 length = print_formatted (output , "[%s,%06uZ] " , time_str ,
322321 ms * 1000U + us );
0 commit comments