From f87f3c9cfc5924742236bee606cc2107475968ce Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 15 Feb 2019 16:22:50 +0100 Subject: Fix ASSERTs when calling beginRemoveRows with out of bounds parameters. The last param must be the last row, not the row count. --- src/ksvnwidgets/models/commitmodel.cpp | 49 +++++++++++++++++++-------------- src/svnfrontend/models/svnitemmodel.cpp | 6 ++-- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/ksvnwidgets/models/commitmodel.cpp b/src/ksvnwidgets/models/commitmodel.cpp index 4b5be8a..ac9d1ff 100644 --- a/src/ksvnwidgets/models/commitmodel.cpp +++ b/src/ksvnwidgets/models/commitmodel.cpp @@ -46,33 +46,42 @@ CommitModel::~CommitModel() void CommitModel::setCommitData(const svn::CommitItemList &aList) { - beginRemoveRows(QModelIndex(), 0, m_List.count()); - m_List.clear(); - endRemoveRows(); - - m_List.reserve(aList.size()); - beginInsertRows(QModelIndex(), 0, aList.size() - 1); - for (int j = 0; j < aList.size(); ++j) { - m_List.append(CommitModelNodePtr(new CommitModelNode(aList[j]))); + if (!m_List.isEmpty()) { + beginRemoveRows(QModelIndex(), 0, m_List.count() - 1); + m_List.clear(); + endRemoveRows(); + } + + if (!aList.isEmpty()) { + m_List.reserve(aList.size()); + beginInsertRows(QModelIndex(), 0, aList.size() - 1); + for (int j = 0; j < aList.size(); ++j) { + m_List.append(CommitModelNodePtr(new CommitModelNode(aList[j]))); + } + endInsertRows(); } - endInsertRows(); } void CommitModel::setCommitData(const CommitActionEntries &checked, const CommitActionEntries ¬checked) { - beginRemoveRows(QModelIndex(), 0, m_List.count()); - m_List.clear(); - endRemoveRows(); - - m_List.reserve(checked.size() + notchecked.size()); - beginInsertRows(QModelIndex(), 0, checked.size() + notchecked.size() - 1); - for (int j = 0; j < checked.size(); ++j) { - m_List.append(CommitModelNodePtr(new CommitModelNode(checked[j], true))); + if (!m_List.isEmpty()) { + beginRemoveRows(QModelIndex(), 0, m_List.count() - 1); + m_List.clear(); + endRemoveRows(); } - for (int j = 0; j < notchecked.size(); ++j) { - m_List.append(CommitModelNodePtr(new CommitModelNode(notchecked[j], false))); + + const int totalSize = checked.size() + notchecked.size(); + if (totalSize > 0) { + m_List.reserve(totalSize); + beginInsertRows(QModelIndex(), 0, totalSize - 1); + for (int j = 0; j < checked.size(); ++j) { + m_List.append(CommitModelNodePtr(new CommitModelNode(checked[j], true))); + } + for (int j = 0; j < notchecked.size(); ++j) { + m_List.append(CommitModelNodePtr(new CommitModelNode(notchecked[j], false))); + } + endInsertRows(); } - endInsertRows(); } int CommitModel::ActionColumn()const diff --git a/src/svnfrontend/models/svnitemmodel.cpp b/src/svnfrontend/models/svnitemmodel.cpp index 0c76e50..8e99e64 100644 --- a/src/svnfrontend/models/svnitemmodel.cpp +++ b/src/svnfrontend/models/svnitemmodel.cpp @@ -173,9 +173,11 @@ void SvnItemModel::setRootNodeStat(const svn::StatusPtr &stat) void SvnItemModel::clear() { int numRows = m_Data->m_rootNode->childList().count(); - beginRemoveRows(QModelIndex(), 0, numRows); + if (numRows > 0) + beginRemoveRows(QModelIndex(), 0, numRows - 1); m_Data->clear(); - endRemoveRows(); + if (numRows > 0) + endRemoveRows(); } void SvnItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last) -- cgit v1.1