summaryrefslogtreecommitdiffstats
path: root/profile-widget/tankitem.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-04 19:39:47 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commitfd23c3d9085a4cd288b95ea414f58f3ad1ac92f1 (patch)
treef16afda47369894055c68489f0c87efc6555af35 /profile-widget/tankitem.cpp
parent2d637f2528ec94710d6c6f7e15568073323c74c1 (diff)
downloadsubsurface-fd23c3d9085a4cd288b95ea414f58f3ad1ac92f1.tar.gz
Profile: don't crash when there are no cylinders
TankItem would happily access a non-existing cylinder and crash. But freedives for example have no cylinders. Thus, handle that situation gracefully by exiting early if there is no cylinder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/tankitem.cpp')
-rw-r--r--profile-widget/tankitem.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp
index 8cd53b5d4..e3233184c 100644
--- a/profile-widget/tankitem.cpp
+++ b/profile-widget/tankitem.cpp
@@ -32,11 +32,6 @@ TankItem::TankItem(QObject *parent) :
hAxis = nullptr;
}
-TankItem::~TankItem()
-{
- free(pInfoEntry);
-}
-
void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d)
{
// If there is nothing to plot, quit early.
@@ -93,6 +88,10 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
qDeleteAll(rects);
rects.clear();
+ // Bail if there are no cylinders
+ if (displayed_dive.cylinders.nr <= 0)
+ return;
+
// get the information directly from the displayed_dive (the dc always exists)
struct divecomputer *dc = get_dive_dc(&displayed_dive, dc_number);