diff src/gtk/transfer.c @ 246:290d00853950

2003-8-4 Brian Masney <masneyb@gftp.org> * src/gtk/transfer.c (update_file_status) - fix possible division by 0
author masneyb
date Tue, 05 Aug 2003 01:54:03 +0000
parents 251845fc1ef1
children 2ad324cf4930
line wrap: on
line diff
--- a/src/gtk/transfer.c	Tue Aug 05 01:40:49 2003 +0000
+++ b/src/gtk/transfer.c	Tue Aug 05 01:54:03 2003 +0000
@@ -1293,7 +1293,7 @@
 {
   char totstr[100], dlstr[100], gotstr[50], ofstr[50];
   int hours, mins, secs, pcent, st;
-  off_t remaining_secs;
+  unsigned long remaining_secs, lkbs;
   gftp_file * tempfle;
   struct timeval tv;
 
@@ -1303,8 +1303,10 @@
   gettimeofday (&tv, NULL);
 
   remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024;
-  if (tdata->kbs > 0)
-    remaining_secs /= (off_t) tdata->kbs;
+
+  lkbs = (unsigned long) tdata->kbs;
+  if (lkbs > 0)
+    remaining_secs /= lkbs;
 
   hours = remaining_secs / 3600;
   remaining_secs -= hours * 3600;
@@ -1318,8 +1320,9 @@
       return;
     }
 
-  pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0);
-  if (pcent < 0 || pcent > 100)
+  if ((double) tdata->total_bytes > 0)
+    pcent = (int) ((double) (tdata->trans_bytes + tdata->resumed_bytes) / (double) tdata->total_bytes * 100.0);
+  else
     pcent = 0;
 
   g_snprintf (totstr, sizeof (totstr),
@@ -1338,8 +1341,10 @@
           if (tdata->curfle->next != NULL)
             {
               remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024;
-              if (tdata->kbs > 0)
-                remaining_secs /= (off_t) tdata->kbs;
+
+              lkbs = (unsigned long) tdata->kbs;
+              if (lkbs > 0)
+                remaining_secs /= lkbs;
 
               hours = remaining_secs / 3600;
               remaining_secs -= hours * 3600;