From: Wayne Davison Date: Thu, 13 Jan 2022 03:50:58 +0000 (-0800) Subject: Avoid a -8 in the progress output's remaining time X-Git-Tag: v3.2.4pre2~9 X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=8c4ceb3b86749523573fec0df38a3b315575735c;p=rsync.git 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. --- 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;