From 81787792d0a85c1bc58419536ac48e50731cbdd8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 13 Mar 2023 21:49:45 +1100 Subject: [PATCH] Fix crash when pasting at buffer end Fixes #4844 --- src/normal.cc | 2 ++ test/regression/4844-crash-on-empty-paste/cmd | 1 + test/regression/4844-crash-on-empty-paste/out | 2 ++ 3 files changed, 5 insertions(+) create mode 100644 test/regression/4844-crash-on-empty-paste/cmd create mode 100644 test/regression/4844-crash-on-empty-paste/out diff --git a/src/normal.cc b/src/normal.cc index e3fdee16..02cea4ef 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -662,6 +662,8 @@ BufferCoord paste_pos(Buffer& buffer, BufferCoord min, BufferCoord max, PasteMod switch (mode) { case PasteMode::Append: + if (buffer.is_end(max)) + return max; return linewise ? std::min(buffer.line_count(), max.line+1) : buffer.char_next(max); case PasteMode::Insert: return linewise ? min.line : min; diff --git a/test/regression/4844-crash-on-empty-paste/cmd b/test/regression/4844-crash-on-empty-paste/cmd new file mode 100644 index 00000000..61d9d426 --- /dev/null +++ b/test/regression/4844-crash-on-empty-paste/cmd @@ -0,0 +1 @@ +Cpp diff --git a/test/regression/4844-crash-on-empty-paste/out b/test/regression/4844-crash-on-empty-paste/out new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/test/regression/4844-crash-on-empty-paste/out @@ -0,0 +1,2 @@ + +