The attached patch will cause ws_percenttitle() to do nothing if the relevant variables have not been initialized. This is what the code did before I changed it. I changed it because it seemed that the code was making allowances for things that should not happen and I thought an assert would be more appropriate. Though, I guess doing thing this way will make the code more robust against future changes (and thus make the Windows port less of a maintenance burden). The patch also clamps the percentage value instead of just returning when it's out-of-range. This is so it will update the title to display the percentage as 100 in the arcane case when the previous percentage was < 100 and the new percentage is > 100. It also includes Gisle Vanem's fix for retr.c.

[I know my assignment is pending but hopefully this patch is small enough to squeak-by until it's been processed.]


2004-03-02 David Fritz <[EMAIL PROTECTED]>


        * retr.c (fd_read_body): Under Windows, only call
        ws_percenttitle() if verbose.  Fix by Gisle Vanem.

        * mswindows.c (ws_percenttitle): Guard against future changes by
        doing nothing if the proper variables have not been initialized.
        Clamp percentage value.





Index: src/mswindows.c
===================================================================
RCS file: /pack/anoncvs/wget/src/mswindows.c,v
retrieving revision 1.27
diff -u -r1.27 mswindows.c
--- src/mswindows.c     2004/02/26 14:34:17     1.27
+++ src/mswindows.c     2004/03/03 03:21:27
@@ -180,19 +180,24 @@
 void
 ws_percenttitle (double percentage_float)
 {
-  int percentage = (int) percentage_float;
+  int percentage;
 
-  /* Only update the title when the percentage has changed.  */
-  if (percentage == old_percentage)
+  if (!title_buf || !curr_url)
     return;
 
-  old_percentage = percentage;
+  percentage = (int) percentage_float;
 
+  /* Clamp percentage value.  */
+  if (percentage < 0)
+    percentage = 0;
   if (percentage > 100)
+    percentage = 100;
+
+  /* Only update the title when the percentage has changed.  */
+  if (percentage == old_percentage)
     return;
 
-  assert (title_buf != NULL);
-  assert (curr_url != NULL);
+  old_percentage = percentage;
 
   sprintf (title_buf, "Wget [%d%%] %s", percentage, curr_url);
   SetConsoleTitle (title_buf);
Index: src/retr.c
===================================================================
RCS file: /pack/anoncvs/wget/src/retr.c,v
retrieving revision 1.84
diff -u -r1.84 retr.c
--- src/retr.c  2003/12/14 13:35:27     1.84
+++ src/retr.c  2004/03/03 03:21:31
@@ -311,7 +311,7 @@
       if (progress)
        progress_update (progress, ret, wtimer_read (timer));
 #ifdef WINDOWS
-      if (toread > 0)
+      if (opt.verbose && toread > 0)
        ws_percenttitle (100.0 *
                         (startpos + sum_read) / (startpos + toread));
 #endif





Reply via email to