]> granicus.if.org Git - vim/commitdiff
patch 8.2.4151: reading beyond the end of a line v8.2.4151
authorBram Moolenaar <Bram@vim.org>
Thu, 20 Jan 2022 12:10:48 +0000 (12:10 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 20 Jan 2022 12:10:48 +0000 (12:10 +0000)
Problem:    Reading beyond the end of a line.
Solution:   For block insert only use the offset for correcting the length.

src/ops.c
src/testdir/test_visual.vim
src/version.c

index a9968024901ec1dc8ff2e5cf7eeaeb7c2e1edb0b..e0fa344d8ee622307e863f64aace7fd39e9eda4c 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -529,24 +529,9 @@ block_insert(
        }
 
        if (has_mbyte && spaces > 0)
-       {
-           int off;
+           // avoid copying part of a multi-byte character
+           offset -= (*mb_head_off)(oldp, oldp + offset);
 
-           // Avoid starting halfway a multi-byte character.
-           if (b_insert)
-           {
-               off = (*mb_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 = (*mb_head_off)(oldp, oldp + offset);
-               offset -= off;
-           }
-       }
        if (spaces < 0)  // can happen when the cursor was moved
            spaces = 0;
 
index b438fa1e66c612ff8495b241025ee2a4060fcf27..a187aa8e085e7554d44308f1231de0d15dca7578 100644 (file)
@@ -1309,5 +1309,14 @@ 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\<C-V>GI" .. repeat('0', 1320) .. "\<Esc>"
+  bwipe!
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 53f1619f94d48b8d7cbdc1ba3f854268142d88a0..227eaa958e2bbbaa370f22d738bf46e25478ceef 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4151,
 /**/
     4150,
 /**/