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>
This commit is contained in:
Miika Turkia 2015-02-03 20:44:36 +02:00 committed by Dirk Hohndel
parent d34965135a
commit 6f795a0059

View file

@ -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);
}