Prevent array access out of bounds

This commit is contained in:
Jan Käberich 2021-11-01 19:15:22 +01:00
parent 1b9feeca1f
commit 8972af3f53

View File

@ -430,6 +430,8 @@ void TraceXYPlot::draw(QPainter &p)
if(i == 0) { if(i == 0) {
// only draw tick lines for primary axis // only draw tick lines for primary axis
if (pref.Graphs.Color.Ticks.Background.enabled) { if (pref.Graphs.Color.Ticks.Background.enabled) {
if (j%2)
{
int yCoordTop = Util::Scale<double>(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace); int yCoordTop = Util::Scale<double>(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace);
int yCoordBot = Util::Scale<double>(YAxis[i].ticks[j-1], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace); int yCoordBot = Util::Scale<double>(YAxis[i].ticks[j-1], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace);
if(yCoordTop > yCoordBot) { if(yCoordTop > yCoordBot) {
@ -437,8 +439,6 @@ void TraceXYPlot::draw(QPainter &p)
yCoordBot = yCoordTop; yCoordBot = yCoordTop;
yCoordTop = buf; yCoordTop = buf;
} }
if (j%2)
{
p.setBrush(pref.Graphs.Color.Ticks.Background.background); p.setBrush(pref.Graphs.Color.Ticks.Background.background);
p.setPen(pref.Graphs.Color.Ticks.Background.background); p.setPen(pref.Graphs.Color.Ticks.Background.background);
auto rect = QRect(plotAreaLeft+1, yCoordTop+1, plotAreaWidth-2, yCoordBot-yCoordTop-2); auto rect = QRect(plotAreaLeft+1, yCoordTop+1, plotAreaWidth-2, yCoordBot-yCoordTop-2);