From a17a0345cf80bb326e5c35b438d6922979df14bc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 31 Dec 2019 12:45:55 +1100 Subject: [PATCH] Fix replacing at begining of buffer Fixes #3275 --- src/selection.cc | 2 +- test/regression/3275-crash-on-replace-at-buffer-start/cmd | 1 + test/regression/3275-crash-on-replace-at-buffer-start/in | 1 + test/regression/3275-crash-on-replace-at-buffer-start/out | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 test/regression/3275-crash-on-replace-at-buffer-start/cmd create mode 100644 test/regression/3275-crash-on-replace-at-buffer-start/in create mode 100644 test/regression/3275-crash-on-replace-at-buffer-start/out diff --git a/src/selection.cc b/src/selection.cc index 781f7c4f..d637e007 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -413,7 +413,7 @@ void SelectionList::insert(ConstArrayView strings, InsertMode mode, auto& min = sel.min(); auto& max = sel.max(); min = range.begin; - max = m_buffer->char_prev(range.end); + max = range.end > range.begin ? m_buffer->char_prev(range.end) : range.begin; } else { diff --git a/test/regression/3275-crash-on-replace-at-buffer-start/cmd b/test/regression/3275-crash-on-replace-at-buffer-start/cmd new file mode 100644 index 00000000..331bae08 --- /dev/null +++ b/test/regression/3275-crash-on-replace-at-buffer-start/cmd @@ -0,0 +1 @@ +R diff --git a/test/regression/3275-crash-on-replace-at-buffer-start/in b/test/regression/3275-crash-on-replace-at-buffer-start/in new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/regression/3275-crash-on-replace-at-buffer-start/in @@ -0,0 +1 @@ +foo diff --git a/test/regression/3275-crash-on-replace-at-buffer-start/out b/test/regression/3275-crash-on-replace-at-buffer-start/out new file mode 100644 index 00000000..c1cccefc --- /dev/null +++ b/test/regression/3275-crash-on-replace-at-buffer-start/out @@ -0,0 +1 @@ +oo