summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Lubomir I. Ivanov <neolit123@gmail.com>2013-10-13 16:20:32 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-13 11:31:25 -0700
commita2a93ff04b26b9b3da96d780c3540451493f0858 (patch)
tree8a14300f71dcd0c4c29833631862e9ecdd734542 /qt-ui
parentd23266ad5119264b0e8c8de0d9edd76c491e0d84 (diff)
downloadsubsurface-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.cpp14
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()