From 30e3fdb9cc1bdb421db67be06feffc3173e6b187 Mon Sep 17 00:00:00 2001 From: Santiago Gil Date: Thu, 2 Mar 2017 10:10:21 -0300 Subject: [PATCH] Fix overflow in MoodbarProxyStyle (fixes #5638) (#5643) --- src/moodbar/moodbarproxystyle.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/moodbar/moodbarproxystyle.cpp b/src/moodbar/moodbarproxystyle.cpp index 200756fea..25a6fec25 100644 --- a/src/moodbar/moodbarproxystyle.cpp +++ b/src/moodbar/moodbarproxystyle.cpp @@ -270,17 +270,20 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc, case SC_SliderHandle: { const QStyleOptionSlider* slider_opt = qstyleoption_cast(opt); - int x = 0; + int x_offset = 0; /* slider_opt->{maximum,minimum} can have the value 0 (their default values), so this check avoids a division by 0. */ if (slider_opt->maximum > slider_opt->minimum) { - x = (slider_opt->sliderValue - slider_opt->minimum) * - (opt->rect.width() - kArrowWidth) / - (slider_opt->maximum - slider_opt->minimum); + qint64 slider_delta = slider_opt->sliderValue - slider_opt->minimum; + qint64 slider_range = slider_opt->maximum - slider_opt->minimum; + int rectangle_effective_width = opt->rect.width() - kArrowWidth; + + qint64 x = slider_delta * rectangle_effective_width / slider_range; + x_offset = static_cast(x); } - return QRect(QPoint(opt->rect.left() + x, opt->rect.top()), + return QRect(QPoint(opt->rect.left() + x_offset, opt->rect.top()), QSize(kArrowWidth, kArrowHeight)); }