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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-10-21 00:06:08 +02:00 committed by bstoeger
parent 063a20a406
commit 687f65bf77

View file

@ -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;
}