diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-21 16:07:53 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-11-21 16:00:09 +0000 |
commit | 7475b073fb8084cf1304cea8a1781e74204a0a11 (patch) | |
tree | a341ec5993c7f3d4f0cd441fa82661b5c901baad /src/libs/3rdparty/cplusplus | |
parent | b298c981f8b294d9c681304297549ed024f07c3f (diff) |
CPlusPlus: Fix finding end of raw string literal
The employed algorithm lacked proper backtracking, potentially causing us
to miss the delimiter altogether.
Change-Id: I7993c3c27d034925bd884e192779c85c54be9ec4
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs/3rdparty/cplusplus')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Lexer.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libs/3rdparty/cplusplus/Lexer.cpp b/src/libs/3rdparty/cplusplus/Lexer.cpp index deafe432b6..62a95f455a 100644 --- a/src/libs/3rdparty/cplusplus/Lexer.cpp +++ b/src/libs/3rdparty/cplusplus/Lexer.cpp @@ -838,16 +838,16 @@ void Lexer::scanRawStringLiteral(Token *tok, unsigned char hint) bool Lexer::scanUntilRawStringLiteralEndPrecise() { - int matchLen = 0; + QByteArray slidingWindow; + slidingWindow.reserve(_expectedRawStringSuffix.size()); while (_yychar) { - if (_yychar == _expectedRawStringSuffix.at(matchLen)) { - if (++matchLen == _expectedRawStringSuffix.length()) { - _expectedRawStringSuffix.clear(); - yyinp(); - return true; - } - } else { - matchLen = 0; + slidingWindow.append(_yychar); + if (slidingWindow.size() > _expectedRawStringSuffix.size()) + slidingWindow.removeFirst(); + if (slidingWindow == _expectedRawStringSuffix) { + _expectedRawStringSuffix.clear(); + yyinp(); + return true; } yyinp(); } |