Commit 10d47bd6 authored by Agata Cacko's avatar Agata Cacko

Change order in conditions in while() in KoZoomAction

Before this commit, while loop would first check the value of the
array in a specific index and only later if the index is in range.
That shouldn't lead to any problems per se unless the array is very
short, because it always starts from the other end of the array and
the loop ends before the index can fall out of range.
However it seems like it triggered some statis analysis tool and it
might potentially deceive a future programmer if some of the external
conditions (like the starting index) changes.
This commit reverses the order of the conditions so the index is checked

parent fe4d0840
......@@ -232,8 +232,9 @@ qreal KoZoomAction::nextZoomLevel() const
const qreal eps = 1e-5;
int i = 0;
while (d->effectiveZoom > d->sliderLookup[i] - eps &&
i < d->sliderLookup.size() - 1) i++;
while (i < d->sliderLookup.size() - 1 && d->effectiveZoom > d->sliderLookup[i] - eps) {
return qMax(d->effectiveZoom, d->sliderLookup[i]);
......@@ -242,7 +243,7 @@ qreal KoZoomAction::prevZoomLevel() const
const qreal eps = 1e-5;
int i = d->sliderLookup.size() - 1;
while (d->effectiveZoom < d->sliderLookup[i] + eps && i > 0) i--;
while (i > 0 && d->effectiveZoom < d->sliderLookup[i] + eps) i--;
return qMin(d->effectiveZoom, d->sliderLookup[i]);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment