diff --git a/src/plugins/texteditor/semantichighlighter.cpp b/src/plugins/texteditor/semantichighlighter.cpp index 0e541e8f41c..ba36dc9c1a8 100644 --- a/src/plugins/texteditor/semantichighlighter.cpp +++ b/src/plugins/texteditor/semantichighlighter.cpp @@ -125,8 +125,13 @@ void TextEditor::SemanticHighlighter::clearExtraAdditionalFormatsUntilEnd( } QTextDocument *doc = highlighter->document(); - QTC_ASSERT(lastBlockNumber + 1 < doc->blockCount(), return); - QTextBlock b = doc->findBlockByNumber(lastBlockNumber + 1); + + const int firstBlockToClear = lastBlockNumber + 1; + if (firstBlockToClear == doc->blockCount()) + return; + QTC_ASSERT(firstBlockToClear < doc->blockCount(), return); + + QTextBlock b = doc->findBlockByNumber(firstBlockToClear); while (b.isValid()) { highlighter->setExtraAdditionalFormats(b, QList());