Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 43de035a authored by Albert Astals Cid's avatar Albert Astals Cid

Fix crash/assert on opening files with similar paths

In KateFileTreeModel::handleDuplicitRootDisplay we need to check if check_root has been removed in the loop of rdir, if it has there's no need to remove it on the nrdir branch, doing so asserts on debug builds and on release builds it creates a broken tree structure that will crash later when trying to use it.

Doesn't crash anymore, added new test that passes, old tests still pass.

Acked by Michal Humpula and Christoph Cullmann

BUGS: 347578
REVIEW: 123793
parent df495cb1
......@@ -295,6 +295,23 @@ void FileTreeModelTest::buildTree_data()
<< ResultNode("foo.txt")))
);
QTest::newRow("bug347578") << ( QList<DummyDocument *>()
<< new DummyDocument("file:///f/g/a/b/c/d/e.txt")
<< new DummyDocument("file:///f/g/a/t/b/c/d/e.txt")
) << (
ResultNode()
<< (ResultNode("a", true)
<< (ResultNode("b", true)
<< (ResultNode("c", true)
<< (ResultNode("d", true)
<< ResultNode("e.txt"))))
<< (ResultNode("t", true)
<< (ResultNode("b", true)
<< (ResultNode("c", true)
<< (ResultNode("d", true)
<< ResultNode("e.txt"))))))
);
QTest::newRow("levels") << ( QList<DummyDocument *>()
<< new DummyDocument("file:///c/a/foo.txt")
<< new DummyDocument("file:///c/b/bar.txt")
......
......@@ -1131,6 +1131,7 @@ void KateFileTreeModel::handleDuplicitRootDisplay(ProxyItemDir *init)
if (check_root->display() == root->display()) {
bool changed = false;
bool check_root_removed = false;
const QString rdir = root->path().section(QLatin1Char('/'), 0, -2);
if (!rdir.isEmpty()) {
......@@ -1153,6 +1154,7 @@ void KateFileTreeModel::handleDuplicitRootDisplay(ProxyItemDir *init)
const QString xy = rdir + QLatin1Char('/');
if (node->path().startsWith(xy)) {
beginRemoveRows(QModelIndex(), node->row(), node->row());
check_root_removed = node == check_root;
m_root->remChild(node);
endRemoveRows();
insertItemInto(irdir, node);
......@@ -1163,21 +1165,23 @@ void KateFileTreeModel::handleDuplicitRootDisplay(ProxyItemDir *init)
changed = true;
}
const QString nrdir = check_root->path().section(QLatin1Char('/'), 0, -2);
if (!nrdir.isEmpty()) {
beginRemoveRows(QModelIndex(), check_root->row(), check_root->row());
m_root->remChild(check_root);
endRemoveRows();
if (!check_root_removed) {
const QString nrdir = check_root->path().section(QLatin1Char('/'), 0, -2);
if (!nrdir.isEmpty()) {
beginRemoveRows(QModelIndex(), check_root->row(), check_root->row());
m_root->remChild(check_root);
endRemoveRows();
ProxyItemDir *irdir = new ProxyItemDir(nrdir);
beginInsertRows(QModelIndex(), m_root->childCount(), m_root->childCount());
m_root->addChild(irdir);
endInsertRows();
ProxyItemDir *irdir = new ProxyItemDir(nrdir);
beginInsertRows(QModelIndex(), m_root->childCount(), m_root->childCount());
m_root->addChild(irdir);
endInsertRows();
insertItemInto(irdir, check_root);
insertItemInto(irdir, check_root);
rootsToCheck.push(irdir);
changed = true;
rootsToCheck.push(irdir);
changed = true;
}
}
if (changed) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment