summaryrefslogtreecommitdiff
blob: fa12c2db868dcf6e502acbf26da24f32d6394153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
From f87f3c9cfc5924742236bee606cc2107475968ce Mon Sep 17 00:00:00 2001
From: David Faure <faure@kde.org>
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 &notchecked)
 {
-    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