From 6a1e2cd8c23df47833db55856c5e27c2e198aa6e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 4 Aug 2019 19:49:43 +0200 Subject: Desktop: support no-cylinders in dive information tab The tab was crashing if there were no cylinders because 1) per_cylinder_mean_depth() would access non-existing cylinders. 2) TabDiveInformation::updateProfile() would access a non-existing mean. Fix both of these crash conditions by checking whether the dive actually has cylinders. Signed-off-by: Berthold Stoeger --- core/dive.c | 3 +++ desktop-widgets/tab-widgets/TabDiveInformation.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/dive.c b/core/dive.c index 24fa8780d..7255416ac 100644 --- a/core/dive.c +++ b/core/dive.c @@ -753,6 +753,9 @@ void per_cylinder_mean_depth(const struct dive *dive, struct divecomputer *dc, i bool *used_cylinders; int num_used_cylinders; + if (dive->cylinders.nr <= 0) + return; + for (i = 0; i < dive->cylinders.nr; i++) mean[i] = duration[i] = 0; if (!dc) diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index afa427bdc..6fabc3bb3 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -82,7 +82,7 @@ void TabDiveInformation::updateProfile() ui->diveTimeText->setText(get_dive_duration_string(current_dive->duration.seconds, tr("h"), tr("min"), tr("sec"), " ", current_dive->dc.divemode == FREEDIVE)); - ui->sacText->setText( mean[0] ? SACs : QString()); + ui->sacText->setText(current_dive->cylinders.nr > 0 && mean[0] ? SACs : QString()); if (current_dive->surface_pressure.mbar == 0) { ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box -- cgit v1.2.3-70-g09d2