Editor: fix crashing on updating snippet selections

The final selection is not tracked in m_selections and needs to be
handled explicitly. Also add an assert preventing unconditionally
accessing an out of bounds element of m_selections.

Fixes: QTCREATORBUG-28631
Change-Id: I1898418b1126bdaffccbdf0e483e2c659d191917
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2023-01-02 12:22:42 +01:00
parent bd679b61d1
commit f0dba78f48

View File

@@ -38,8 +38,13 @@ void SnippetOverlay::setFinalSelection(const QTextCursor &cursor, const QColor &
void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
{
const int &currentIndex = indexForCursor(cursor);
if (currentIndex == m_finalSelectionIndex) {
accept();
return;
}
if (currentIndex < 0)
return;
QTC_ASSERT(currentIndex < m_selections.size(), return);
const QString &currentText = cursorForIndex(currentIndex).selectedText();
const QList<int> &equivalents = m_variables.value(m_selections[currentIndex].variableIndex);
for (int i : equivalents) {