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,15 +430,15 @@ 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) {
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);
if(yCoordTop > yCoordBot) {
auto buf = yCoordBot;
yCoordBot = yCoordTop;
yCoordTop = buf;
}
if (j%2) if (j%2)
{ {
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);
if(yCoordTop > yCoordBot) {
auto buf = yCoordBot;
yCoordBot = yCoordTop;
yCoordTop = buf;
}
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);