From a2a93ff04b26b9b3da96d780c3540451493f0858 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Sun, 13 Oct 2013 16:20:32 +0300 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/models.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'qt-ui/models.cpp') 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() -- cgit v1.2.3-70-g09d2