]> sjero.net Git - wget/commitdiff
[svn] Abort if wtimer_update is called on an uninitialized timer.
authorhniksic <devnull@localhost>
Sat, 8 Nov 2003 16:13:54 +0000 (08:13 -0800)
committerhniksic <devnull@localhost>
Sat, 8 Nov 2003 16:13:54 +0000 (08:13 -0800)
On the other hand, allow wtimer_read on such a timer.

src/ChangeLog
src/utils.c

index 40415df857760fbd593152f2db5307a1ccee45f0..5af1bd4ad6201a038aa90d1925b4205d4143eca9 100644 (file)
@@ -1,3 +1,10 @@
+2003-11-08  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * utils.c (wtimer_allocate): Bless the use of wtimer_read on a
+       timer that has merely been allocated because get_contents() does
+       that.
+       (wtimer_update): Abort if the timer is not initialized.
+
 2003-11-08  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * retr.c (get_contents): Pass the timer to limit_bandwidth().
index 1559b2796ebc996d4ff73e4f4bb212ad81b6ea12..343e110eda08e159f743b7994322156c0c05189e 100644 (file)
@@ -1318,6 +1318,9 @@ typedef ULARGE_INTEGER wget_sys_time;
 #endif
 
 struct wget_timer {
+  /* Whether the start time has been initialized. */
+  int initialized;
+
   /* The starting point in time which, subtracted from the current
      time, yields elapsed time. */
   wget_sys_time start;
@@ -1331,13 +1334,15 @@ struct wget_timer {
   double elapsed_pre_start;
 };
 
-/* Allocate a timer.  It is not legal to do anything with a freshly
-   allocated timer, except call wtimer_reset() or wtimer_delete().  */
+/* Allocate a timer.  Calling wtimer_read on the timer will return
+   zero.  It is not legal to call wtimer_update with a freshly
+   allocated timer -- use wtimer_reset first.  */
 
 struct wget_timer *
 wtimer_allocate (void)
 {
   struct wget_timer *wt = xnew (struct wget_timer);
+  xzero (*wt);
   return wt;
 }
 
@@ -1408,6 +1413,7 @@ wtimer_reset (struct wget_timer *wt)
   wtimer_sys_set (&wt->start);
   wt->elapsed_last = 0;
   wt->elapsed_pre_start = 0;
+  wt->initialized = 1;
 }
 
 static double
@@ -1444,6 +1450,8 @@ wtimer_update (struct wget_timer *wt)
   wget_sys_time now;
   double elapsed;
 
+  assert (wt->initialized != 0);
+
   wtimer_sys_set (&now);
   elapsed = wt->elapsed_pre_start + wtimer_sys_diff (&now, &wt->start);