From fd23c3d9085a4cd288b95ea414f58f3ad1ac92f1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 4 Aug 2019 19:39:47 +0200 Subject: 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 --- profile-widget/tankitem.cpp | 9 ++++----- profile-widget/tankitem.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'profile-widget') 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); diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h index ff86f787d..73994444b 100644 --- a/profile-widget/tankitem.h +++ b/profile-widget/tankitem.h @@ -15,7 +15,6 @@ class TankItem : public QObject, public QGraphicsRectItem public: explicit TankItem(QObject *parent = 0); - ~TankItem(); void setHorizontalAxis(DiveCartesianAxis *horizontal); void setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d); -- cgit v1.2.3-70-g09d2