Blame SOURCES/0001-patch-8.2.4151-reading-beyond-the-end-of-a-line.patch

da4393
diff --git a/src/ops.c b/src/ops.c
da4393
index 88992b6..80e0ea1 100644
da4393
--- a/src/ops.c
da4393
+++ b/src/ops.c
da4393
@@ -527,24 +527,8 @@ block_insert(
da4393
 	}
da4393
 
da4393
 	if (has_mbyte && spaces > 0)
da4393
-	{
da4393
-	    int off;
da4393
-
da4393
-	    // Avoid starting halfway a multi-byte character.
da4393
-	    if (b_insert)
da4393
-	    {
da4393
-		off = (*mb_head_off)(oldp, oldp + offset + spaces);
da4393
-		spaces -= off;
da4393
-		count -= off;
da4393
-	    }
da4393
-	    else
da4393
-	    {
da4393
-		// spaces fill the gap, the character that's at the edge moves
da4393
-		// right
da4393
-		off = (*mb_head_off)(oldp, oldp + offset);
da4393
-		offset -= off;
da4393
-	    }
da4393
-	}
da4393
+	    // avoid copying part of a multi-byte character
da4393
+	    offset -= (*mb_head_off)(oldp, oldp + offset);
da4393
 
da4393
 	// Make sure the allocated size matches what is actually copied below.
da4393
 	newp = alloc(STRLEN(oldp) + spaces + s_len
da4393
diff --git a/src/testdir/test_utf8.vim b/src/testdir/test_utf8.vim
da4393
index 5454e43..bedec20 100644
da4393
--- a/src/testdir/test_utf8.vim
da4393
+++ b/src/testdir/test_utf8.vim
da4393
@@ -7,7 +7,7 @@ func Test_visual_block_insert()
da4393
   new
da4393
   call setline(1, ["aaa", "あああ", "bbb"])
da4393
   exe ":norm! gg0l\<C-V>jjIx\<Esc>"
da4393
-  call assert_equal(['axaa', 'xあああ', 'bxbb'], getline(1, '$'))
da4393
+  call assert_equal(['axaa', ' xあああ', 'bxbb'], getline(1, '$'))
da4393
   bwipeout!
da4393
 endfunc
da4393
 
da4393
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
da4393
index dc8e376..8de9e3d 100644
da4393
--- a/src/testdir/test_visual.vim
da4393
+++ b/src/testdir/test_visual.vim
da4393
@@ -976,4 +976,13 @@ func Test_visual_block_append_invalid_char()
da4393
   bwipe!
da4393
 endfunc
da4393
 
da4393
+func Test_visual_block_insert_round_off()
da4393
+  new
da4393
+  " The number of characters are tuned to fill a 4096 byte allocated block,
da4393
+  " so that valgrind reports going over the end.
da4393
+  call setline(1, ['xxxxx', repeat('0', 1350), "\t", repeat('x', 60)])
da4393
+  exe "normal gg0\<C-V>GI" .. repeat('0', 1320) .. "\<Esc>"
da4393
+  bwipe!
da4393
+endfunc
da4393
+
da4393
 " vim: shiftwidth=2 sts=2 expandtab