diff options
| author | Maxime Coste <mawww@kakoune.org> | 2023-06-20 13:09:03 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2023-06-20 13:09:03 +1000 |
| commit | d43268fbebab0989015639c4bdc9e31aa137b06a (patch) | |
| tree | 97f5fae0282c211cb6317ada85d3680e57a7dbce /src | |
| parent | e58592f00a61fe05a238bc106cd108f8a57ad291 (diff) | |
Fix invalid access of display line end
When a line only contains non-range atoms we can end-up accessing
past the end atom.
Add a test that shows the issue when run with valgrind, it is
unfortunately quite hard to trigger a crash because the invalidly
accessed byte usually leads to the correct code path being taken
(when != DisplayAtom::Range) so we have only 1 in 255 chance of
triggerring a crash.
Fixes #4927
Diffstat (limited to 'src')
| -rw-r--r-- | src/highlighters.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc index ee772469..65f801cb 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1820,7 +1820,7 @@ struct ForwardHighlighterApplier { auto& line = *cur_line; auto first = std::find_if(cur_atom, line.end(), [&](auto&& atom) { return atom.has_buffer_range() and atom.end() > begin; }); - if (first->type() == DisplayAtom::Range and first->begin() < begin) + if (first != line.end() and first->type() == DisplayAtom::Range and first->begin() < begin) first = ++line.split(first, begin); auto idx = first - line.begin(); |
