Avoid a -8 in the progress output's remaining time
authorWayne Davison <wayne@opencoder.net>
Thu, 13 Jan 2022 03:50:58 +0000 (19:50 -0800)
committerWayne Davison <wayne@opencoder.net>
Thu, 13 Jan 2022 04:04:32 +0000 (20:04 -0800)
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
progress.c

diff --git a/NEWS.md b/NEWS.md
index 8bab61cfb9060a4fa5c6c501b0b57cf361d67005..4eebaa44cb76c59810cfca7e9579343c08a5b61d 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
    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.
index 8da528622a20faf214fc8b3c32703ce372ae7c90..6e39ce995dc6cdfb750b81c35d6f50aef39ebcbb 100644 (file)
@@ -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;