From: Jonathan Liu Date: Tue, 21 Feb 2012 04:54:25 +0000 (+1100) Subject: QElapsedTimer/Win: Fix 64-bit integer overflow X-Git-Tag: qt-v5.0.0-alpha1~868 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8ecf3ad034c759be753a625ac97800df53cb401;p=profile%2Fivi%2Fqtbase.git 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 Reviewed-by: Thiago Macieira (cherry picked from commit f30a91ba9d98de1a0ebee5608ba289ac35871a8c) --- diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp index b1faf22..8171a27 100644 --- a/src/corelib/tools/qelapsedtimer_win.cpp +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -83,7 +83,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;