mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
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: 7b13fb557b
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> {
|
auto find_span_of_type = [&](auto i, CppToken::Type type, CppToken::Type not_type, Direction direction) -> Optional<size_t> {
|
||||||
size_t nesting_level = 0;
|
size_t nesting_level = 0;
|
||||||
bool forward = direction == Direction::Forward;
|
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 = document.spans().at(i);
|
||||||
auto span_token_type = (CppToken::Type)((FlatPtr)span.data);
|
auto span_token_type = (CppToken::Type)((FlatPtr)span.data);
|
||||||
if (span_token_type == not_type) {
|
if (span_token_type == not_type) {
|
||||||
|
@ -86,7 +97,18 @@ void CppSyntaxHighlighter::highlight_matching_token_pair()
|
||||||
if (nesting_level-- <= 0)
|
if (nesting_level-- <= 0)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forward) {
|
||||||
|
++i;
|
||||||
|
if (i >= document.spans().size())
|
||||||
|
return {};
|
||||||
|
} else {
|
||||||
|
if (i == 0)
|
||||||
|
return {};
|
||||||
|
--i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue