From e2c0c2fbe5efd5da5524553189e376d53194a037 Mon Sep 17 00:00:00 2001
From: Tim Rühsen <tim.ruehsen@gmx.de>
Date: Thu, 12 Dec 2019 16:14:57 +0100
Subject: [PATCH] * src/progress.c (print_row_stats): Fix two integer overflows

---
 src/progress.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/progress.c b/src/progress.c
index 96d00398..4217c620 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -303,6 +303,9 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
     /* For last row also count bytes accumulated after last dot */
     bytes_displayed += dp->accumulated;
 
+  if (bytes_displayed < 0)
+    bytes_displayed = 0;
+
   if (dp->total_length)
     {
       /* Round to floor value to provide gauge how much data *has*
@@ -338,9 +341,9 @@ print_row_stats (struct dot_progress *dp, double dltime, bool last)
          Belperchinov-Shabanski's "wget-new-percentage" patch.  */
       if (dp->total_length)
         {
-          wgint bytes_remaining = dp->total_length - bytes_displayed;
+          wgint bytes_remaining = dp->total_length > bytes_displayed ? dp->total_length - bytes_displayed : 0;
           /* The quantity downloaded in this download run. */
-          wgint bytes_sofar = bytes_displayed - dp->initial_length;
+          wgint bytes_sofar = bytes_displayed > dp->initial_length ? bytes_displayed - dp->initial_length : 1;
           double eta = dltime * bytes_remaining / bytes_sofar;
           if (eta < 0)
             eta = 0;
-- 
2.19.1.windows.1

