core: fix deletion of events in fixup_dc_events()

If there were more than one redundant event in the 60 sec range,
the event would be deleted multiple time, leading to a crash.

Only mark for deletion once.

Moreover, don't consider events that were already marked for
deletion, because that would mean that redundant events all 59 secs
would lead to all events (but the first one) deleted.

Finally, optimize the loop by stopping once the 60 sec limit
is reached.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-08-18 09:02:07 +02:00 committed by bstoeger
parent 0dc47882cb
commit 26c594382e

View file

@ -757,9 +757,14 @@ static void fixup_dc_events(struct divecomputer &dc)
continue;
for (int idx2 = idx - 1; idx2 > 0; --idx2) {
const auto &prev = dc.events[idx2];
if (prev.name == event.name && prev.flags == event.flags &&
event.time.seconds - prev.time.seconds < 61)
if (event.time.seconds - prev.time.seconds > 60)
break;
if (range_contains(to_delete, idx2))
continue;
if (prev.name == event.name && prev.flags == event.flags) {
to_delete.push_back(idx);
break;
}
}
}
// Delete from back to not invalidate indexes