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 <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2024-01-16 09:20:33 +01:00
parent d5a5088996
commit 03958b5806

View File

@@ -782,6 +782,7 @@ SearchResultItems symbolOccurrencesInDeclarationComments(
QList<Text::Range> symbolOccurrencesInText(const QTextDocument &doc, QStringView text, int offset,
const QString &symbolName)
{
QTC_ASSERT(!symbolName.isEmpty(), return QList<Text::Range>());
QList<Text::Range> ranges;
int index = 0;
while (true) {