From e58592f00a61fe05a238bc106cd108f8a57ad291 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 19 Jun 2023 12:55:55 +1000 Subject: [PATCH] Fix highlighters being applied to empty display buffers In some cases such as with folding we can end-up with regions not having any atoms to highlight which can trigger a crash as we assume display buffers not to be empty Fixes #4926 --- src/highlighters.cc | 3 +++ test/regression/4926-crash-with-fold-and-ranges/cmd | 1 + test/regression/4926-crash-with-fold-and-ranges/in | 4 ++++ test/regression/4926-crash-with-fold-and-ranges/rc | 6 ++++++ 4 files changed, 14 insertions(+) create mode 100644 test/regression/4926-crash-with-fold-and-ranges/cmd create mode 100644 test/regression/4926-crash-with-fold-and-ranges/in create mode 100644 test/regression/4926-crash-with-fold-and-ranges/rc diff --git a/src/highlighters.cc b/src/highlighters.cc index d2daa085..ee772469 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1840,6 +1840,9 @@ struct ForwardHighlighterApplier cur_atom = cur_line->begin(); } + if (region_lines.empty()) + return; + region_display.compute_range(); highlighter.highlight(context, region_display, {begin, end}); diff --git a/test/regression/4926-crash-with-fold-and-ranges/cmd b/test/regression/4926-crash-with-fold-and-ranges/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/4926-crash-with-fold-and-ranges/cmd @@ -0,0 +1 @@ + diff --git a/test/regression/4926-crash-with-fold-and-ranges/in b/test/regression/4926-crash-with-fold-and-ranges/in new file mode 100644 index 00000000..5c93113c --- /dev/null +++ b/test/regression/4926-crash-with-fold-and-ranges/in @@ -0,0 +1,4 @@ +{[foo]} +{[bar]} +{[baz]} +%( ) diff --git a/test/regression/4926-crash-with-fold-and-ranges/rc b/test/regression/4926-crash-with-fold-and-ranges/rc new file mode 100644 index 00000000..62d98e01 --- /dev/null +++ b/test/regression/4926-crash-with-fold-and-ranges/rc @@ -0,0 +1,6 @@ +declare-option range-specs fold %val{timestamp} 1.1,3.8|folded + +add-highlighter buffer/regions regions +add-highlighter buffer/regions/curly region \{ \} regions +add-highlighter buffer/regions/curly/brace region \[ \] fill green +add-highlighter buffer/fold replace-ranges fold