@@ -407,20 +407,21 @@ void stats_update_memory_usage(int index, int pid)
407407 }
408408}
409409
410- static char * printDate (const time_t * t )
411- {
412- static char ts [22 ]; // Fixme : solve without internal static buffer
410+ #define DATE_BUFFER_SIZE 22
413411
412+ static char * printDate (const time_t * t , char * buf , size_t buf_size )
413+ {
414414 if ((* t ) > 0 )
415415 {
416- strftime (ts , sizeof ( ts ) , "%Y-%m-%d %H:%M:%S" , localtime (t ));
416+ strftime (buf , buf_size , "%Y-%m-%d %H:%M:%S" , localtime (t ));
417417 }
418418 else
419419 {
420- strcpy (ts , "Never" );
420+ strncpy (buf , "Never" , buf_size - 1 );
421+ buf [buf_size - 1 ] = '\0' ;
421422 }
422423
423- return ts ;
424+ return buf ;
424425}
425426
426427void stats_print_to_file (int index , const char * app_name )
@@ -435,10 +436,11 @@ void stats_print_to_file(int index, const char *app_name)
435436 return ;
436437 }
437438
439+ char date_buf [DATE_BUFFER_SIZE ];
438440 fprintf (fp , "Statistics for App %d %s:\n" , index , app_name );
439- fprintf (fp , "Started at: %s\n" , printDate (& stats [index ].started_at ));
440- fprintf (fp , "Crashed at: %s\n" , printDate (& stats [index ].crashed_at ));
441- fprintf (fp , "Heartbeat reset at: %s\n" , printDate (& stats [index ].heartbeat_reset_at ));
441+ fprintf (fp , "Started at: %s\n" , printDate (& stats [index ].started_at , date_buf , sizeof ( date_buf ) ));
442+ fprintf (fp , "Crashed at: %s\n" , printDate (& stats [index ].crashed_at , date_buf , sizeof ( date_buf ) ));
443+ fprintf (fp , "Heartbeat reset at: %s\n" , printDate (& stats [index ].heartbeat_reset_at , date_buf , sizeof ( date_buf ) ));
442444 fprintf (fp , "Start count: %zu\n" , stats [index ].start_count );
443445 fprintf (fp , "Crash count: %zu\n" , stats [index ].crash_count );
444446 fprintf (fp , "Heartbeat reset count: %zu\n" , stats [index ].heartbeat_reset_count );
0 commit comments