diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2013-10-13 16:20:32 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-10-13 11:31:25 -0700 |
commit | a2a93ff04b26b9b3da96d780c3540451493f0858 (patch) | |
tree | 8a14300f71dcd0c4c29833631862e9ecdd734542 /qt-ui | |
parent | d23266ad5119264b0e8c8de0d9edd76c491e0d84 (diff) | |
download | subsurface-a2a93ff04b26b9b3da96d780c3540451493f0858.tar.gz |
Models: fix two potential crashes
CylinderModels::setDive() and WeightModel::setDive() have
potential to pass the 'last' argument to beginInsertRows() as
a negative number which triggers an assert that 'last' cannot
be smaller than 'first'.
Patch attempts to fix that by only calling beginInsertRows()
when there is at least one row to insert.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/models.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 3d1936eea..df2732cc4 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -323,12 +323,13 @@ void CylindersModel::setDive(dive* d) break; } } - - beginInsertRows(QModelIndex(), 0, amount-1); rows = amount; current = d; changed = false; - endInsertRows(); + if (amount > 0) { + beginInsertRows(QModelIndex(), 0, amount - 1); + endInsertRows(); + } } Qt::ItemFlags CylindersModel::flags(const QModelIndex& index) const @@ -504,12 +505,13 @@ void WeightModel::setDive(dive* d) break; } } - - beginInsertRows(QModelIndex(), 0, amount-1); rows = amount; current = d; changed = false; - endInsertRows(); + if (amount > 0) { + beginInsertRows(QModelIndex(), 0, amount - 1); + endInsertRows(); + } } WSInfoModel* WSInfoModel::instance() |