From a3d0983f5909c37205cf0bdd4c4eba15d26d58c9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 5 Jan 2017 08:10:53 +0100 Subject: QProgressBar: don't lose precision in text() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When qreal is float, it cannot represent all values an int can take, so we may lose precision in the expression qreal(d->value) - d->minimum as opposed to the exact result qint64(d->value) - d->minimum' For lack of trying, I do not know of a value where this would change the resulting 'progress' value, but better be safe than sorry, and use the 64-bit integer expression instead. Found while reviewing integer arithmetic in QProgressBar as part of the fix for QTBUG-57857. While touching the line, make the (intended) double → int truncation explicit, by using a static_cast. Change-Id: I03dbfce24c709310c3bbad9487a2bf0d1d78137a Reviewed-by: David Faure --- src/widgets/widgets/qprogressbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index be6091f499..64f19047b6 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -485,7 +485,7 @@ QString QProgressBar::text() const return result; } - int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; + const auto progress = static_cast((qint64(d->value) - d->minimum) * 100.0 / totalSteps); result.replace(QLatin1String("%p"), locale.toString(progress)); return result; } -- cgit v1.2.3