summaryrefslogtreecommitdiffstats
path: root/qt-ui/diveplanner.cpp
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2015-02-03 20:44:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-03 11:27:35 -0800
commit6f795a0059f5b1540d62bab30bc62422717420bb (patch)
tree098f53bbf5bcbde8a75ab6c5297662ac4fbde6fa /qt-ui/diveplanner.cpp
parentd34965135a3b3f8fd887bb1d2a6083fb2f181fb0 (diff)
downloadsubsurface-6f795a0059f5b1540d62bab30bc62422717420bb.tar.gz
Fix crash when moving divepoints rigorously
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@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/diveplanner.cpp')
-rw-r--r--qt-ui/diveplanner.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 2ee168413..67b84d0bd 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);
}