From 8c4ceb3b86749523573fec0df38a3b315575735c Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Wed, 12 Jan 2022 19:50:58 -0800 Subject: [PATCH] Avoid a -8 in the progress output's remaining time If the double "remain" value is so large that it overflows an int, make the estimated seconds output as :00 instead of :-8. Similar for the estimated remaining minutes. Support larger hours values. --- NEWS.md | 5 +++++ progress.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8bab61cf..4eebaa44 100644 --- a/NEWS.md +++ b/NEWS.md @@ -88,6 +88,11 @@ check to see if the allowed time is over, which should make rsync exit more consistently. + - Tweak the snprintf() in progress.c that turns the remaining time into a + HHHH:MM:SS value to avoid putting a -8 into the SS or MM spots when the + remaining seconds is so large that it overflows the integer arithmetic + trying to perform a modulus. + ### ENHANCEMENTS: - Use openssl's `-verify_hostname` option in the rsync-ssl script. diff --git a/progress.c b/progress.c index 8da52862..6e39ce99 100644 --- a/progress.c +++ b/progress.c @@ -118,10 +118,10 @@ static void rprint_progress(OFF_T ofs, OFF_T size, struct timeval *now, int is_l if (remain < 0) strlcpy(rembuf, " ??:??:??", sizeof rembuf); else { - snprintf(rembuf, sizeof rembuf, "%4d:%02d:%02d", - (int) (remain / 3600.0), - (int) (remain / 60.0) % 60, - (int) remain % 60); + snprintf(rembuf, sizeof rembuf, "%4lu:%02u:%02u", + (unsigned long) (remain / 3600.0), + (unsigned int) (remain / 60.0) % 60, + (unsigned int) remain % 60); } output_needs_newline = 0; -- 2.47.2