summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorJonathan Liu <net147@gmail.com>2012-02-21 15:54:25 +1100
committerQt by Nokia <qt-info@nokia.com>2012-02-21 13:29:50 +0100
commitf30a91ba9d98de1a0ebee5608ba289ac35871a8c (patch)
tree41e9a3273795427263f35649c6722e8938cc1f0a /src/corelib/tools
parentc87445a2b75264e633d2f358534109ee8ca27ca9 (diff)
QElapsedTimer/Win: Fix 64-bit integer overflow
The ticksToNanoseconds function in qelapsedtimer_win.cpp multiplies ticks from performance counter with 1000000000 which can sometimes result in 64-bit integer overflow. This can cause the elapsed time to reset or jump around. Task-number: QTBUG-23150 Change-Id: I464503e03cbe64e13906e773beafbf88e7dc256a Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qelapsedtimer_win.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp
index 11cc14090a..4635bb88c4 100644
--- a/src/corelib/tools/qelapsedtimer_win.cpp
+++ b/src/corelib/tools/qelapsedtimer_win.cpp
@@ -81,7 +81,9 @@ static inline qint64 ticksToNanoseconds(qint64 ticks)
{
if (counterFrequency > 0) {
// QueryPerformanceCounter uses an arbitrary frequency
- return ticks * 1000000000 / counterFrequency;
+ qint64 seconds = ticks / counterFrequency;
+ qint64 nanoSeconds = (ticks - seconds * counterFrequency) * 1000000000 / counterFrequency;
+ return seconds * 1000000000 + nanoSeconds;
} else {
// GetTickCount(64) return milliseconds
return ticks * 1000000;