@@ -46,6 +46,8 @@ static char *progress2string(char *buf, size_t s, int progress_1000);
4646
4747/* Used to separate internal errors from actual dev replace ioctl results. */
4848#define BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT -1
49+ /* Buffer size for ETA string display */
50+ #define ETA_STR_SIZE 80
4951
5052static const char * replace_dev_result2string (__u64 result )
5153{
@@ -422,7 +424,8 @@ static int print_replace_status(int fd, const char *path, int once)
422424 char string1 [80 ];
423425 char string2 [80 ];
424426 char string3 [80 ];
425- char eta_str [80 ];
427+ char eta_str [ETA_STR_SIZE ];
428+ struct tm eta_tm_buf ;
426429
427430 for (;;) {
428431 args .cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS ;
@@ -470,10 +473,10 @@ static int print_replace_status(int fd, const char *path, int once)
470473 /* Only show ETA if we have a reasonable estimate */
471474 if (remaining_time > 0 && total_time > elapsed_time ) {
472475 eta_time = current_time + remaining_time ;
473- struct tm eta_tm_buf ;
474476 struct tm * eta_tm = localtime_r (& eta_time , & eta_tm_buf );
475- strftime (eta_str , sizeof (eta_str ), "ETA: %a %b %d %H:%M:%S %Y" , eta_tm );
476- num_chars += printf (", %s" , eta_str );
477+ if (strftime (eta_str , sizeof (eta_str ), "ETA: %a %b %d %H:%M:%S %Y" , eta_tm ) > 0 ) {
478+ num_chars += printf (", %s" , eta_str );
479+ }
477480 }
478481 }
479482 }
0 commit comments