Fix possible divide by zero in QMacStyle

[ChangeLog][Widgets][QMacStyle] Fixed a possible divide by zero crash.

Task-number: QTBUG-43398
Change-Id: I8b5c6fd87d07eb42ad43e8c2405b7cad19372b86
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
This commit is contained in:
Liang Qi 2015-01-07 12:50:14 +01:00 committed by Jani Heikkinen
parent 49fd3511f5
commit cd389e4584

View File

@ -1675,13 +1675,14 @@ void QMacStylePrivate::getSliderInfo(QStyle::ComplexControl cc, const QStyleOpti
else
tdi->max = 10 * slider->rect.height();
if (usePlainKnob || slider->orientation == Qt::Horizontal) {
int range = slider->maximum - slider->minimum;
if (range == 0) {
tdi->value = 0;
} else if (usePlainKnob || slider->orientation == Qt::Horizontal) {
int endsCorrection = usePlainKnob ? 25 : 10;
tdi->value = (tdi->max + 2 * endsCorrection) * (slider->sliderPosition - slider->minimum)
/ (slider->maximum - slider->minimum) - endsCorrection;
tdi->value = (tdi->max + 2 * endsCorrection) * (slider->sliderPosition - slider->minimum) / range - endsCorrection;
} else {
tdi->value = (tdi->max + 30) * (slider->sliderPosition - slider->minimum)
/ (slider->maximum - slider->minimum) - 20;
tdi->value = (tdi->max + 30) * (slider->sliderPosition - slider->minimum) / range - 20;
}
}
tdi->attributes = kThemeTrackShowThumb;