We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 958

Summary: Timer Underflow
Product: SDL Reporter: dino puller <dino.puller>
Component: timerAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 1.2   
Hardware: All   
OS: All   

Description dino puller 2010-02-22 06:53:55 UTC
If you try to set a delay < 10ms a variable may got to underflow into 
void SDL_ThreadedTimerCheck(void)

I suggest to change:
		ms = t->interval - SDL_TIMESLICE;   
		next = t->next;
		if ( (int)(now - t->last_alarm) > (int)ms ) {

with:
		if ( (int)(now - t->last_alarm + SDL_TIMESLICE) > (int)ms ) {


bye,
   Dino
Comment 1 dino puller 2010-02-24 01:15:19 UTC
(In reply to comment #0)
> If you try to set a delay < 10ms a variable may got to underflow into 
> void SDL_ThreadedTimerCheck(void)
> 
> I suggest to change:
>         ms = t->interval - SDL_TIMESLICE;   
>         next = t->next;
>         if ( (int)(now - t->last_alarm) > (int)ms ) {
> 
> with:
>         if ( (int)(now - t->last_alarm + SDL_TIMESLICE) > (int)ms ) {
> 
> 
> bye,
>    Dino


The suggested line was:
     if ( (int)(now - t->last_alarm + SDL_TIMESLICE) >  t->interval ) {

Anyway  t->interval is always rounded to be at least SDL_TIMESLICE, so no underflow will happen.