From 03958b5806c79cd0bd6b996488184b400a585b04 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 16 Jan 2024 09:20:33 +0100 Subject: [PATCH] CppEditor: avoid endless loop in symbol name lookup Passing and empty text to QString::indexOf returns a 0 index and we advance the start index by the length of the symbol name so we check again from the start. Just assert if we pass an empty symbol name to symbolOccurrencesInText and return an empty list of occurrences to avoid this. Task-number: QTCREATORBUG-30155 Change-Id: I6ad672a3dc2ae9d937fdc436874d07c00997fbf5 Reviewed-by: Christian Kandeler --- src/plugins/cppeditor/cpptoolsreuse.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/cppeditor/cpptoolsreuse.cpp b/src/plugins/cppeditor/cpptoolsreuse.cpp index 06bf220382a..fa1df1e6fe7 100644 --- a/src/plugins/cppeditor/cpptoolsreuse.cpp +++ b/src/plugins/cppeditor/cpptoolsreuse.cpp @@ -782,6 +782,7 @@ SearchResultItems symbolOccurrencesInDeclarationComments( QList symbolOccurrencesInText(const QTextDocument &doc, QStringView text, int offset, const QString &symbolName) { + QTC_ASSERT(!symbolName.isEmpty(), return QList()); QList ranges; int index = 0; while (true) {