aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/cylindermodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-01-30 14:33:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-30 19:33:21 +0200
commit62b869b24ada9f6e2e94980774d228dafe1472e2 (patch)
treed6552129a6fed94e54f6186b0a18367cac32bdb0 /qt-models/cylindermodel.cpp
parent906cce9e88453332806b8d5b620eb9c5a78a99f0 (diff)
downloadsubsurface-62b869b24ada9f6e2e94980774d228dafe1472e2.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/cylindermodel.cpp')
-rw-r--r--qt-models/cylindermodel.cpp5
1 files changed, 5 insertions, 0 deletions
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) {