Problem: 1616218

Title: (TDispatcher -GetWaitTicks) Return very large value

Received: Jan 2 1997 11:46AM


I found TMyApp::DoIdle isn't called as expected if application is in background. Although application's fIdleFreq is 0, TDispatcher::GetWaitTicks sometimes returns very large value. The bug is in TDispatcher::GetWaitTicks.
compositeTicks = MinMax(0L, iter->NextIdle() - ::TickCount(), compositeTicks);
Since TickCount is declared that it returns UInt32, this expression fails if NextIdle returned `past' time.

"iter->NextIdle() - (long)::TickCount()" works.


Fix:

MacApp's calculation of idle times would sometimes cause overflow of the signed value that was being used in their calculation. MacApp now uses unsigned longs for the intermediate calculations. Files affected: UDispatcher.cp/.h UEventHandler.cp/.h

The following variables need to be unsign long.

   long fLastUpTime;           // time of last mouse up event
   long fNextSpaceMessage;     // time when next low space message should
                               // be displayed
A few temporary variables in TDispatcher::GetWaitTicks() need to be unsigned long.

Corrected UDispatcher/UEventHandler.cp/.h and also corrected UODDispatcher.cp/.h. For the record, TickCount used to be a signed long value, but somewhere along the way the headers started defining it as unsigned and we had not percolated the changes thoughout macapp.