From 6ae7a7b4a1e048ad8b91b122fde09d9c5c0203b0 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 26 Nov 2024 09:21:10 +0100 Subject: [PATCH] Git: Add nullptr checks Add some checks for possible nullptr as we saw a crash in Sentry (Event Id: c5d14c9a5f9e4e6fb1e14c3cdb756c76) Task-number: QTCREATORBUG-32186 Change-Id: I5c30751ffaa10ccdd218f0aef7de4b4feacdb887 Reviewed-by: David Schulz (cherry picked from commit a6768807dce99bfd52cd73dcd5960d95f8b5ec0d) Reviewed-by: Eike Ziller --- src/plugins/git/branchmodel.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index aca355f2cb3..88cc12a4e4a 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -281,6 +281,7 @@ QModelIndex BranchModel::parent(const QModelIndex &index) const return {}; BranchNode *node = indexToNode(index); + QTC_ASSERT(node, return {}); if (node->parent == d->rootNode) return {}; return nodeToIndex(node->parent, ColumnBranch); @@ -553,6 +554,7 @@ QString BranchModel::sha(const QModelIndex &idx) const if (!idx.isValid()) return {}; BranchNode *node = indexToNode(idx); + QTC_ASSERT(node, return {}); return node->sha; } @@ -561,6 +563,8 @@ QDateTime BranchModel::dateTime(const QModelIndex &idx) const if (!idx.isValid()) return {}; BranchNode *node = indexToNode(idx); + QTC_ASSERT(node, return {}); + return node->dateTime; } @@ -569,6 +573,8 @@ bool BranchModel::isHead(const QModelIndex &idx) const if (!idx.isValid()) return false; BranchNode *node = indexToNode(idx); + QTC_ASSERT(node, return false); + return node == d->headNode; } @@ -577,6 +583,8 @@ bool BranchModel::isLocal(const QModelIndex &idx) const if (!idx.isValid()) return false; BranchNode *node = indexToNode(idx); + QTC_ASSERT(node, return false); + return node == d->headNode ? false : node->isLocal(); } @@ -585,6 +593,8 @@ bool BranchModel::isLeaf(const QModelIndex &idx) const if (!idx.isValid()) return false; BranchNode *node = indexToNode(idx); + QTC_ASSERT(node, return false); + return node->isLeaf(); } @@ -770,6 +780,8 @@ void BranchModel::refreshCurrentBranch() { const QModelIndex currentIndex = currentBranch(); BranchNode *node = indexToNode(currentIndex); + QTC_ASSERT(node, return); + updateUpstreamStatus(node); } @@ -888,6 +900,8 @@ QModelIndex BranchModel::nodeToIndex(BranchNode *node, int column) const { if (node == d->rootNode) return {}; + QTC_ASSERT(node->parent, return {}); + return createIndex(node->parent->rowOf(node), column, static_cast(node)); } @@ -895,6 +909,8 @@ void BranchModel::removeNode(const QModelIndex &idx) { QModelIndex nodeIndex = idx; // idx is a leaf, so count must be 0. BranchNode *node = indexToNode(nodeIndex); + QTC_ASSERT(node, return); + while (node->count() == 0 && node->parent != d->rootNode) { BranchNode *parentNode = node->parent; const QModelIndex parentIndex = nodeToIndex(parentNode, ColumnBranch);