]> sjero.net Git - wget/commitdiff
[svn] Don't allow initial_length to exceed total_length.
authorhniksic <devnull@localhost>
Thu, 11 Apr 2002 18:51:26 +0000 (11:51 -0700)
committerhniksic <devnull@localhost>
Thu, 11 Apr 2002 18:51:26 +0000 (11:51 -0700)
Published in <sxssn62dq99.fsf@florida.arsdigita.de>.

src/ChangeLog
src/progress.c

index 56713018992a87e7f12b9febd32d7f2aec206c70..590f3861e17804f0fc9fc77a57091d729fbf347b 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-11  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * progress.c (bar_create): If INITIAL is larger than TOTAL, fix
+       TOTAL.
+       (bar_finish): Likewise.
+
 2002-04-11  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * html-url.c (tag_handle_form): New function.  Pick up form
 2002-04-11  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * html-url.c (tag_handle_form): New function.  Pick up form
index de5d16a31cda85ae036ca51a362b2fa57be83ed6..644c1b2b9dc1571bb3d3dbabbbc5c4bad27f6dbc 100644 (file)
@@ -461,6 +461,11 @@ bar_create (long initial, long total)
 
   memset (bp, 0, sizeof (*bp));
 
 
   memset (bp, 0, sizeof (*bp));
 
+  /* In theory, our callers should take care of this pathological
+     case, but it can sometimes happen. */
+  if (initial > total)
+    total = initial;
+
   bp->initial_length = initial;
   bp->total_length   = total;
 
   bp->initial_length = initial;
   bp->total_length   = total;
 
@@ -493,7 +498,7 @@ bar_update (void *progress, long howmuch, long dltime)
        adjust bp->total_length to the new reality, so that the code in
        create_image() that depends on total size being smaller or
        equal to the expected size doesn't abort.  */
        adjust bp->total_length to the new reality, so that the code in
        create_image() that depends on total size being smaller or
        equal to the expected size doesn't abort.  */
-    bp->total_length = bp->count + bp->initial_length;
+    bp->total_length = bp->initial_length + bp->count;
 
   /* This code attempts to determine the current download speed.  We
      measure the speed over the interval of approximately three
 
   /* This code attempts to determine the current download speed.  We
      measure the speed over the interval of approximately three
@@ -565,6 +570,11 @@ bar_finish (void *progress, long dltime)
 {
   struct bar_progress *bp = progress;
 
 {
   struct bar_progress *bp = progress;
 
+  if (bp->total_length > 0
+      && bp->count + bp->initial_length > bp->total_length)
+    /* See bar_update() for explanation. */
+    bp->total_length = bp->initial_length + bp->count;
+
   create_image (bp, dltime);
   display_image (bp->buffer);
 
   create_image (bp, dltime);
   display_image (bp->buffer);