LibGUI: Fix overflow crash in highlighter
This commit is contained in:
parent
d58cf1a05d
commit
7b13fb557b
Notes:
sideshowbarker
2024-07-19 08:46:43 +09:00
Author: https://github.com/oriko1010 Commit: https://github.com/SerenityOS/serenity/commit/7b13fb557b0 Pull-request: https://github.com/SerenityOS/serenity/pull/1416
1 changed files with 23 additions and 1 deletions
|
@ -77,7 +77,18 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
auto find_span_of_type = [&](auto i, CppToken::Type type, CppToken::Type not_type, Direction direction) -> Optional<size_t> {
|
||||
size_t nesting_level = 0;
|
||||
bool forward = direction == Direction::Forward;
|
||||
for (forward ? ++i : --i; forward ? (i < document.spans().size()) : (i >= 0); forward ? ++i : --i) {
|
||||
|
||||
if (forward) {
|
||||
++i;
|
||||
if (i >= document.spans().size())
|
||||
return {};
|
||||
} else {
|
||||
if (i == 0)
|
||||
return {};
|
||||
--i;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
auto& span = document.spans().at(i);
|
||||
auto span_token_type = (CppToken::Type)((FlatPtr)span.data);
|
||||
if (span_token_type == not_type) {
|
||||
|
@ -86,7 +97,18 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
|||
if (nesting_level-- <= 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
if (forward) {
|
||||
++i;
|
||||
if (i >= document.spans().size())
|
||||
return {};
|
||||
} else {
|
||||
if (i == 0)
|
||||
return {};
|
||||
--i;
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue