From eb5d4f2a15b26b0ae1d2cff08aa4bdb465b2970a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 10 Feb 2023 19:00:49 +0100 Subject: [PATCH] desktop: fix multi-dive editing of cylinders 3629a87 changed the handling of cylinders in multi-dives edit. Not only should the cylinders be the "same", but also at the same position. The code did not check whether the edited dives even had that many cylinders, leading to a null-pointer dereference. Check whether the cylinder exists before comparing it. Fixes #3578. Signed-off-by: Berthold Stoeger --- CHANGELOG.md | 1 + commands/command_edit.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac3538d40..bf767eb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +desktop: fix crash on cylinder update of multiple dives desktop: use dynamic tank use drop down in equipment tab and planner desktop: fix brightness configuration for OSTC4 equipment: Use 'diluent' as default gas use type if the dive mode is 'CCR' diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 3a9b23556..09d7f40b9 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1199,19 +1199,24 @@ EditCylinderBase::EditCylinderBase(int index, bool currentDiveOnly, bool nonProt cyl.reserve(dives.size()); for (dive *d: dives) { + if (index >= d->cylinders.nr) + continue; if (nonProtectedOnly && is_cylinder_prot(d, index)) continue; + // We checked that the cylinder exists above. + const cylinder_t &cylinder = *get_cylinder(d, index); if (d != current && - (!same_cylinder_size(orig, *get_cylinder(d, index)) || !same_cylinder_type(orig, *get_cylinder(d, index)))) + (!same_cylinder_size(orig, cylinder) || !same_cylinder_type(orig, cylinder))) { // when editing cylinders, we assume that the user wanted to edit the 'n-th' cylinder // and we only do edit that cylinder, if it was the same type as the one in the current dive continue; + } divesNew.push_back(d); // that's silly as it's always the same value - but we need this vector of indices in the case where we add // a cylinder to several dives as the spot will potentially be different in different dives indexes.push_back(index); - cyl.push_back(clone_cylinder(*get_cylinder(d, index))); + cyl.push_back(clone_cylinder(cylinder)); } dives = std::move(divesNew); }