From 62b869b24ada9f6e2e94980774d228dafe1472e2 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 30 Jan 2020 14:33:27 +0100 Subject: CylindersModel: don't crash if accessing non-existing cylinder It shouldn't happen, but currently we overwrite the displayed_dive without updating the CylindersModel. Thus, CylindersModel may now crash when the new displayed_dive has less cylinders than the old one. For now, catch this condition. Treat the root cause later. Signed-off-by: Berthold Stoeger --- qt-models/cylindermodel.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'qt-models/cylindermodel.cpp') diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp index dd9ac5e69..2ed81ab72 100644 --- a/qt-models/cylindermodel.cpp +++ b/qt-models/cylindermodel.cpp @@ -134,6 +134,11 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const if (!index.isValid() || index.row() >= rows) return QVariant(); + if (index.row() >= displayed_dive.cylinders.nr) { + qWarning("CylindersModel and displayed_dive are out of sync!"); + return QVariant(); + } + const cylinder_t *cyl = get_cylinder(&displayed_dive, index.row()); switch (role) { -- cgit v1.2.3-70-g09d2