]> granicus.if.org Git - vim/commitdiff
patch 8.2.4217: illegal memory access when undo makes Visual area invalid v8.2.4217
authorBram Moolenaar <Bram@vim.org>
Tue, 25 Jan 2022 18:24:00 +0000 (18:24 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 25 Jan 2022 18:24:00 +0000 (18:24 +0000)
Problem:    Illegal memory access when undo makes Visual area invalid.
Solution:   Correct the Visual area after undo.

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

index 9b322fd211b385ec147c9867d09de4ff1552f6aa..b2beda08d0aa84337c0f40c3e593d9900b924910 100644 (file)
@@ -1339,5 +1339,20 @@ func Test_visual_ex_copy_line()
   bwipe!
 endfunc
 
+" This was leaving the end of the Visual area beyond the end of a line.
+" Set 'undolevels' to start a new undo block.
+func Test_visual_undo_deletes_last_line()
+  new
+  call setline(1, ["aaa", "ccc", "dyd"])
+  set undolevels=100
+  exe "normal obbbbbbbbbxbb\<Esc>"
+  set undolevels=100
+  /y
+  exe "normal ggvjfxO"
+  undo
+  normal gNU
+  bwipe!
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 4d186d45325949f2cb942ac7e7bc4ab1f6345561..636144aefd17feb179a0272ca2c66897a9e145be 100644 (file)
@@ -3029,6 +3029,8 @@ u_undo_end(
        }
     }
 #endif
+    if (VIsual_active)
+       check_pos(curbuf, &VIsual);
 
     smsg_attr_keep(0, _("%ld %s; %s #%ld  %s"),
            u_oldcount < 0 ? -u_oldcount : u_oldcount,
index f5f9a2ef9427053c675ddfcf3f8395361891ee61..6685b554f537ebd3a21954eedd10f783a7d72379 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4217,
 /**/
     4216,
 /**/