changeset 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 41af60bc1f88
children f41650dc896c
files ChangeLog src/gtk/transfer.c
diffstat 2 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Aug 05 01:40:49 2003 +0000
+++ b/ChangeLog	Tue Aug 05 01:54:03 2003 +0000
@@ -1,3 +1,6 @@
+2003-8-4 Brian Masney <masneyb@gftp.org>
+	* src/gtk/transfer.c (update_file_status) - fix possible division by 0
+
 2003-8-4 Brian Masney <masneyb@gftp.org>
 	* src/gtk/gftp-gtk.c (CreateMenus) - on startup, select the proper
 	ASCII/binary radio button (looks like an old bug!)
@@ -1430,7 +1433,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.126 2003/08/05 01:40:47 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.127 2003/08/05 01:54:02 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- 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;