[Mono-dev] [PATCH] eglib patch to avoid double overflow in win32 gtimers

Jeffrey Stedfast fejj at novell.com
Wed May 6 12:19:11 EDT 2009


The calculation:
    *microseconds = (gulong)(1000000.0 * (stop - timer->start) / freq);

isn't ideal ordering for long-running timers and may overflow after
multiplying by 1000000.0 but before having a chance to divide by freq. A
simple reordering of operations makes this less likely.

Also, I made it so that it only needs to query the performance counter
frequency once rather than each time. The patch also handles errors
getting the performance counter frequency (currently falls back to freq
= 1, but perhaps it should use freq = 1000000? Does anyone have hardware
where this actually fails?). This prevents possible divide-by-zero
exceptions.

Jeff

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gtimer.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090506/c7e973b7/attachment.bin 


More information about the Mono-devel-list mailing list