From 7830cded770626fc836b04e0877bd64155a7eb59 Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Tue, 30 Jul 2024 10:09:37 +0200 Subject: [PATCH] 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 --- src/traceplot.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traceplot.cpp b/src/traceplot.cpp index 3e3fbb2..95b6347 100644 --- a/src/traceplot.cpp +++ b/src/traceplot.cpp @@ -32,7 +32,7 @@ void TracePlot::paintMid(QPainter &painter, QRect &rect, range_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