From 687f65bf77ccc2c95ee9713742f8fa59058e75ab Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 21 Oct 2022 00:06:08 +0200 Subject: [PATCH] planner: avoid out-of-bound access when initializing the planner For dives with many samples (i.e. logged dives), samples are merged. I'm not exactly sure how this code works, but it does an out-of-bound access in some cases. Avoid that by a simple check. That said, I wonder if this downsampling is a good idea. A user reports that they have logged dives marked as manually added dives. We now load them into edit mode, which means a significant loss of information. Perhaps we should consider dives with more than 100 samples as non-manual dives? Signed-off-by: Berthold Stoeger --- qt-models/diveplannermodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 058bc3821..b10094194 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -147,10 +147,10 @@ void DivePlannerPointsModel::loadFromDive(dive *dIn) break; while (j * plansamples <= i * dc->samples) { const sample &s = dc->sample[j]; - const sample &prev = dc->sample[j-1]; if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) { depthsum += s.depth.mm; - last_sp = prev.setpoint; + if (j > 0) + last_sp = dc->sample[j-1].setpoint; ++samplecount; newtime = s.time; }