[PATCH] Fix a crash when editing manually added dive

Miika Turkia miika.turkia at gmail.com
Thu Oct 8 08:59:37 PDT 2015


I have manually added dives from an ancient version of Subsurface.
Trying to edit these caused Subsurface to crash due to comparison of
string of dc.model that did not exist (to a static string). And further
down the execution path we were crashing as there were no samples
associated with the dive.

See #941

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 qt-models/diveplannermodel.cpp | 7 ++++++-
 qt-ui/mainwindow.cpp           | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 49fc502..b5db3f0 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -78,7 +78,12 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
 	// if yes then the first sample should be marked
 	// if it is we only add the manually entered samples as waypoints to the diveplan
 	// otherwise we have to add all of them
-	bool hasMarkedSamples = d->dc.sample[0].manually_entered;
+
+	bool hasMarkedSamples = false;
+
+	if (d->dc.samples)
+		hasMarkedSamples = d->dc.sample[0].manually_entered;
+
 	// if this dive has more than 100 samples (so it is probably a logged dive),
 	// average samples so we end up with a total of 100 samples.
 	int plansamples = d->dc.samples <= 100 ? d->dc.samples : 100;
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 084c9f1..d0f2f91 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -798,7 +798,7 @@ void MainWindow::on_actionEditDive_triggered()
 	}
 
 	const bool isTripEdit = dive_list()->selectedTrips().count() >= 1;
-	if (!current_dive || isTripEdit || strcmp(current_dive->dc.model, "manually added dive")) {
+	if (!current_dive || isTripEdit || (current_dive->dc.model && strcmp(current_dive->dc.model, "manually added dive"))) {
 		QMessageBox::warning(this, tr("Warning"), tr("Trying to edit a dive that's not a manually added dive."));
 		return;
 	}
-- 
2.1.4



More information about the subsurface mailing list