diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-01-06 07:38:50 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-01-20 17:49:48 +0000 |
commit | 6aa540a1060ce4c9167e380e2f8341cdc536ee51 (patch) | |
tree | b8c2a718dce35ee5ca2e737ebabfcf2bf8083176 /src | |
parent | 69c576badfc1a3d33422dbe74ac575594e378c30 (diff) |
QAndroidStyle: fix UB (signed integer overflow) in AndroidProgressBarControl::drawControl()
The expression 'maximum - minimum' has undefined behavior when
'qint64(maximum) - minimum > INT_MAX'. Use 64-bit arithmetic
instead.
Also fix calculation of the progress when minimum != 0.
Rename QStyleOptionProgressBar* variable to avoid line wraps.
Change-Id: I1d48a7930e7f6d69798c2e878bb0045d55c2f057
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit afefed06952d5edd5c6be4376469b022975930cf)
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/styles/qandroidstyle.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index 4489f36ab7..e34776a343 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -1614,15 +1614,14 @@ void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *o if (!m_progressDrawable) return; - if (const QStyleOptionProgressBar *progressBarOption = - qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { if (m_progressDrawable->type() == QAndroidStyle::Layer) { - const double fraction = progressBarOption->progress / double(progressBarOption->maximum - progressBarOption->minimum); + const double fraction = double(qint64(pb->progress) - pb->minimum) / (qint64(pb->maximum) - pb->minimum); QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); if (clipDrawable->type() == QAndroidStyle::Clip) - static_cast<AndroidClipDrawable *>(clipDrawable)->setFactor(fraction, progressBarOption->orientation); + static_cast<AndroidClipDrawable *>(clipDrawable)->setFactor(fraction, pb->orientation); else - static_cast<AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId, fraction, progressBarOption->orientation); + static_cast<AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId, fraction, pb->orientation); } m_progressDrawable->draw(p, option); } |