CppEditor: Fix crash with adjacent raw string literals

Our lexer is not good at handling newlines embedded in raw string
literals; basically, it sees every continuation line as a new string. So
if such a continuation is followed directly by a new raw string literal,
we have to take care to tell them apart properly. In particular, it can
happen that an end delimiter occurs before an opening delimiter.

Fixes: QTCREATORBUG-24577
Change-Id: I631d0617d85e91f49a25d309d53778da0170eb3b
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2020-09-04 11:43:36 +02:00
parent 913dc6473d
commit b74d620bf0

View File

@@ -396,6 +396,8 @@ bool CppHighlighter::highlightRawStringLiteral(const QStringView &_text, const T
if (text.at(tk.utf16charsEnd() - 1) != '"') if (text.at(tk.utf16charsEnd() - 1) != '"')
return false; return false;
const int endDelimiterOffset = tk.utf16charsEnd() - 1 - delimiter.length(); const int endDelimiterOffset = tk.utf16charsEnd() - 1 - delimiter.length();
if (endDelimiterOffset <= delimiterOffset)
return false;
if (text.mid(endDelimiterOffset, delimiter.length()) != delimiter) if (text.mid(endDelimiterOffset, delimiter.length()) != delimiter)
return false; return false;
if (text.at(endDelimiterOffset - 1) != ')') if (text.at(endDelimiterOffset - 1) != ')')