Dive d/l selection UI: the indices are inclusive, allocate enough space

The array we allocated was one entry too small.

On the flip side, let's just make sure we cannot call this with a negative
range. That would be bad, too.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-01-09 12:03:29 -08:00
parent cd2cee4974
commit 15fb6158bc

View file

@ -629,14 +629,15 @@ Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
void DiveImportedModel::setImportedDivesIndexes(int first, int last) void DiveImportedModel::setImportedDivesIndexes(int first, int last)
{ {
Q_ASSERT(last >= first);
beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex); beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
endRemoveRows(); endRemoveRows();
beginInsertRows(QModelIndex(), 0, last - first); beginInsertRows(QModelIndex(), 0, last - first);
lastIndex = last; lastIndex = last;
firstIndex = first; firstIndex = first;
delete[] checkStates; delete[] checkStates;
checkStates = new bool[last - first]; checkStates = new bool[last - first + 1];
memset(checkStates, true, last - first); memset(checkStates, true, last - first + 1);
endInsertRows(); endInsertRows();
} }