From afbed8cb75af714a636128c4ad7fb4be6edf7727 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 3 Feb 2022 01:22:24 +0000 Subject: [PATCH] vim-patch:8.2.4151: reading beyond the end of a line Problem: Reading beyond the end of a line. Solution: For block insert only use the offset for correcting the length. https://github.com/vim/vim/commit/57df9e8a9f9ae1aafdde9b86b10ad907627a87dc --- src/nvim/ops.c | 15 ++------------- src/nvim/testdir/test_visual.vim | 9 +++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e712aa18b3..c9a99fef84 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -568,19 +568,8 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def } if (spaces > 0) { - int off; - - // Avoid starting halfway through a multi-byte character. - if (b_insert) { - off = utf_head_off(oldp, oldp + offset + spaces); - spaces -= off; - count -= off; - } else { - // spaces fill the gap, the character that's at the edge moves - // right - off = utf_head_off(oldp, oldp + offset); - offset -= off; - } + // avoid copying part of a multi-byte character + offset -= utf_head_off(oldp, oldp + offset); } if (spaces < 0) { // can happen when the cursor was moved spaces = 0; diff --git a/src/nvim/testdir/test_visual.vim b/src/nvim/testdir/test_visual.vim index a2c93bd573..edb72c82e3 100644 --- a/src/nvim/testdir/test_visual.vim +++ b/src/nvim/testdir/test_visual.vim @@ -1271,6 +1271,15 @@ func Test_visual_reselect_with_count() call delete('XvisualReselect') endfunc +func Test_visual_block_insert_round_off() + new + " The number of characters are tuned to fill a 4096 byte allocated block, + " so that valgrind reports going over the end. + call setline(1, ['xxxxx', repeat('0', 1350), "\t", repeat('x', 60)]) + exe "normal gg0\GI" .. repeat('0', 1320) .. "\" + bwipe! +endfunc + " this was leaving the end of the Visual area beyond the end of a line func Test_visual_ex_copy_line() new