[PATCH 1/2] Fix crash when moving divepoints rigorously

Miika Turkia miika.turkia at gmail.com
Tue Feb 3 10:44:36 PST 2015


I have no idea how the index ends up outside the range, but at least
this prevents a crash in this case.

See #784

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 qt-ui/diveplanner.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 2ee1684..67b84d0 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1003,6 +1003,12 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in,
 
 void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
 {
+	/*
+	 * When moving divepoints rigorously, we might end up with index
+	 * out of range, thus returning the last one instead.
+	 */
+	if (row >= divepoints.count())
+		return;
 	divepoints[row] = newData;
 	std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
@@ -1015,6 +1021,12 @@ int DivePlannerPointsModel::size()
 
 divedatapoint DivePlannerPointsModel::at(int row)
 {
+	/*
+	 * When moving divepoints rigorously, we might end up with index
+	 * out of range, thus returning the last one instead.
+	 */
+	if (row >= divepoints.count())
+		return divepoints.at(divepoints.count() - 1);
 	return divepoints.at(row);
 }
 
-- 
1.9.1



More information about the subsurface mailing list