From 8972af3f535e47c7c20b5af0df1ae625230285e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=A4berich?= Date: Mon, 1 Nov 2021 19:15:22 +0100 Subject: [PATCH] Prevent array access out of bounds --- Software/PC_Application/Traces/tracexyplot.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Software/PC_Application/Traces/tracexyplot.cpp b/Software/PC_Application/Traces/tracexyplot.cpp index 0ad2ba8..56f6e75 100644 --- a/Software/PC_Application/Traces/tracexyplot.cpp +++ b/Software/PC_Application/Traces/tracexyplot.cpp @@ -430,15 +430,15 @@ void TraceXYPlot::draw(QPainter &p) if(i == 0) { // only draw tick lines for primary axis if (pref.Graphs.Color.Ticks.Background.enabled) { - int yCoordTop = Util::Scale(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace); - int yCoordBot = Util::Scale(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) { + int yCoordTop = Util::Scale(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace); + int yCoordBot = Util::Scale(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.setPen(pref.Graphs.Color.Ticks.Background.background); auto rect = QRect(plotAreaLeft+1, yCoordTop+1, plotAreaWidth-2, yCoordBot-yCoordTop-2);