CPlusPlus: Fix possible crash

Text may contain special utf characters which in turn lets
the range of the token become different if handled as normal
byte. This would end up in an assert if the QStringView tries
to access a position after the last character of the text.
Amends 242579099a.

Change-Id: Ie52c15e8729f25da850b539a6a55cca134026c3d
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Stenger
2020-09-16 11:41:03 +02:00
parent 90d9cb36f3
commit 7a84381a27

View File

@@ -86,10 +86,9 @@ Tokens SimpleLexer::operator()(const QString &text, int state)
_endedJoined = tk.joined();
break;
}
const QStringView spell = tk.bytesBegin() + tk.bytes() > text.size()
? QStringView(text).mid(tk.bytesBegin())
: QStringView(text).mid(tk.bytesBegin(), tk.bytes());
const QStringView spell = tk.utf16charsBegin() + tk.utf16chars() > text.size()
? QStringView(text).mid(tk.utf16charsBegin())
: QStringView(text).mid(tk.utf16charsBegin(), tk.utf16chars());
lex.setScanAngleStringLiteralTokens(false);
if (tk.newline() && tk.is(T_POUND))