1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-23 16:28:19 +01:00

Merge pull request #5263 from simark/fix-moodbar-crash

moodbar: check QSlider max/min before using them in division
This commit is contained in:
John Maguire 2016-02-18 14:17:58 +00:00
commit 51c1c36934

View File

@ -270,10 +270,15 @@ QRect MoodbarProxyStyle::subControlRect(ComplexControl cc,
case SC_SliderHandle: { case SC_SliderHandle: {
const QStyleOptionSlider* slider_opt = const QStyleOptionSlider* slider_opt =
qstyleoption_cast<const QStyleOptionSlider*>(opt); qstyleoption_cast<const QStyleOptionSlider*>(opt);
int x = 0;
const int x = (slider_opt->sliderValue - slider_opt->minimum) * /* slider_opt->{maximum,minimum} can have the value 0 (their default
(opt->rect.width() - kArrowWidth) / values), so this check avoids a division by 0. */
(slider_opt->maximum - slider_opt->minimum); if (slider_opt->maximum > slider_opt->minimum) {
x = (slider_opt->sliderValue - slider_opt->minimum) *
(opt->rect.width() - kArrowWidth) /
(slider_opt->maximum - slider_opt->minimum);
}
return QRect(QPoint(opt->rect.left() + x, opt->rect.top()), return QRect(QPoint(opt->rect.left() + x, opt->rect.top()),
QSize(kArrowWidth, kArrowHeight)); QSize(kArrowWidth, kArrowHeight));