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 <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2015-02-03 20:44:37 +02:00 committed by Dirk Hohndel
parent 6f795a0059
commit 4f9705f3f5

View file

@ -41,6 +41,16 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
int firstRow = rowCount() - rows.count();
QVector<int> 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]);