- From: Stefan Wiesner <sw@ais-ag.de>
- Date: Mon, 26 Feb 2001 15:10:43 +0100
- To: www-lib@w3.org
Hi,
I think there is a bug in the code of function HTTimer_new if a timer
is already expired when HTTimer_new is called. See description below:
>>> ...
>>> /*
>>> ** Sort new element into list
>>> */
>>> for (cur = last;
>>> (pres = (HTTimer *) HTList_nextObject(cur)) != NULL && pres->expires < expires;
>>> last = cur);
last cur
| |
| |
V |
-------- |
|object|--->timer1 V
| | --------
|next |---------------->|object|--->timer2
-------- | |
|next |--->...
--------
>>> ...
>>> /*
>>> ** add to list if timer is new
>>> */
>>> HTList_addObject(last, (void *)timer);
last cur
| |
| |
V |
-------- |
|object|--->timer1 |
| | -------- |
|next |---------------->|object|--->timer_new V
-------- | | --------
|next |----------------->|object|--->timer2
-------- | |
|next |--->...
--------
>>> ...
>>> /* Check if the timer object has already expired. If so then dispatch */
>>> if (timer->expires <= now) Timer_dispatch(cur, last);
>>> ...
If the 'if' evaluates to 'TRUE', function 'Timer_dispatch' is called
with wrong parameters. As the result, the HTList object pointing to
timer_new gets lost and the callback function of timer2 is called.
To fix this, the previous call of function
'HTList_addObject(last, (void *)timer);' should be replaced by
'cur = HTList_addList(last, (void *)timer);'
One other thing to the Timer handling:
Although it is a good idea to dispatch the timer in function
'HTTimer_new'
when it has already expired, (I think) there is no way to get this
information
from the parameter the function returns. This behaviour may lead to
errors in a calling program. (In fact it has in my program.)
Greetings
Stefan Wiesner
--
Stefan Wiesner
AIS Automations- und Informationssysteme GmbH
Rheinweg 7, 34131 Kassel, Germany
Telefon: +49-561/30859-24, Telefax: +49-561/30859-39
Received on Monday, 26 February 2001 09:35:52 UTC