diff --git a/src/ChangeLog b/src/ChangeLog index 40415df8..5af1bd4a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-11-08 Hrvoje Niksic + + * 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 * retr.c (get_contents): Pass the timer to limit_bandwidth(). diff --git a/src/utils.c b/src/utils.c index 1559b279..343e110e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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);