traceplot: Fix divide by zero crash

Very small files would cause inspectrum to crash with a SIGFPE. In the
end, this is caused by input that let's `samplesPerColumn == 0`. Make
sure this value is at least `1` and it doesn't crash anymore.

Signed-off-by: Johannes Demel <johannes.demel@dedrone.com>
This commit is contained in:
Johannes Demel
2024-07-30 10:09:37 +02:00
parent 6a1ee5a5e5
commit 7830cded77

View File

@@ -32,7 +32,7 @@ void TracePlot::paintMid(QPainter &painter, QRect &rect, range_t<size_t> sampleR
{
if (sampleRange.length() == 0) return;
int samplesPerColumn = sampleRange.length() / rect.width();
int samplesPerColumn = std::max(1UL, sampleRange.length() / rect.width());
int samplesPerTile = tileWidth * samplesPerColumn;
size_t tileID = sampleRange.minimum / samplesPerTile;
size_t tileOffset = sampleRange.minimum % samplesPerTile; // Number of samples to skip from first image tile