From 4f9705f3f54fc14d6b38123160f07015c41f3519 Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Tue, 3 Feb 2015 20:44:37 +0200 Subject: Fix crash when removing an out-of-profile divepoints We can end up having a divepoint that is outside the dive profile. In this case, we used to crash, but this hack prevents the index out of range issue. Fixes #784 Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- qt-ui/diveplanner.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 67b84d0bd..84555bcd6 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -41,6 +41,16 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector &rows) int firstRow = rowCount() - rows.count(); QVector v2 = rows; std::sort(v2.begin(), v2.end(), intLessThan); + + /* + * If we end up having divepoints that are not within the dive + * profile, we need to just skip the removal to prevent + * crashing due to index out of range. + */ + + if (rowCount() >= divepoints.count()) + return; + beginRemoveRows(QModelIndex(), firstRow, rowCount() - 1); for (int i = v2.count() - 1; i >= 0; i--) { divepoints.remove(v2[i]); -- cgit v1.2.3-70-g09d2