From b0060ed79e6978c6bb41ff008b9f36ea14b6d9ac Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 13 Apr 2016 20:48:34 +0100 Subject: [PATCH] Fix modified range computation when erasing multiple times past current buffer end Fixes #654 --- src/selection.cc | 8 ++++++++ test/regression/654-crash-on-undo-after-macro/cmd | 1 + test/regression/654-crash-on-undo-after-macro/in | 1 + test/regression/654-crash-on-undo-after-macro/out | 1 + 4 files changed, 11 insertions(+) create mode 100644 test/regression/654-crash-on-undo-after-macro/cmd create mode 100644 test/regression/654-crash-on-undo-after-macro/in create mode 100644 test/regression/654-crash-on-undo-after-macro/out diff --git a/src/selection.cc b/src/selection.cc index a2b2d1f2..ee849bc4 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -305,6 +305,14 @@ Vector compute_modified_ranges(Buffer& buffer, size_t timestamp) change_it = backward_end; } + const auto end_coord = buffer.end_coord(); + for (auto it = ranges.begin() + prev_size; it != ranges.end(); ++it) + { + it->anchor() = std::min(it->anchor(), end_coord); + it->cursor() = std::min(it->cursor(), end_coord); + } + + kak_assert(std::is_sorted(ranges.begin() + prev_size, ranges.end(), compare_selections)); std::inplace_merge(ranges.begin(), ranges.begin() + prev_size, ranges.end(), compare_selections); ranges.erase(merge_overlapping(ranges.begin(), ranges.end(), dummy, overlaps), ranges.end()); diff --git a/test/regression/654-crash-on-undo-after-macro/cmd b/test/regression/654-crash-on-undo-after-macro/cmd new file mode 100644 index 00000000..6285c43f --- /dev/null +++ b/test/regression/654-crash-on-undo-after-macro/cmd @@ -0,0 +1 @@ +Qxy;dQ3qu diff --git a/test/regression/654-crash-on-undo-after-macro/in b/test/regression/654-crash-on-undo-after-macro/in new file mode 100644 index 00000000..72943a16 --- /dev/null +++ b/test/regression/654-crash-on-undo-after-macro/in @@ -0,0 +1 @@ +aaa diff --git a/test/regression/654-crash-on-undo-after-macro/out b/test/regression/654-crash-on-undo-after-macro/out new file mode 100644 index 00000000..72943a16 --- /dev/null +++ b/test/regression/654-crash-on-undo-after-macro/out @@ -0,0 +1 @@ +aaa