Blame SOURCES/0001-patch-8.2.4217-illegal-memory-access-when-undo-makes.patch

13ea7f
From 8d02ce1ed75d008c34a5c9aaa51b67cbb9d33baa Mon Sep 17 00:00:00 2001
13ea7f
From: Bram Moolenaar <Bram@vim.org>
13ea7f
Date: Tue, 25 Jan 2022 18:24:00 +0000
13ea7f
Subject: [PATCH] patch 8.2.4217: illegal memory access when undo makes Visual
13ea7f
 area invalid
13ea7f
13ea7f
Problem:    Illegal memory access when undo makes Visual area invalid.
13ea7f
Solution:   Correct the Visual area after undo.
13ea7f
---
13ea7f
 src/testdir/test_visual.vim | 15 +++++++++++++++
13ea7f
 src/undo.c                  |  2 ++
13ea7f
 src/version.c               |  2 ++
13ea7f
 3 files changed, 19 insertions(+)
13ea7f
13ea7f
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
13ea7f
index 9b322fd21..b2beda08d 100644
13ea7f
--- a/src/testdir/test_visual.vim
13ea7f
+++ b/src/testdir/test_visual.vim
13ea7f
@@ -1339,5 +1339,20 @@ func Test_visual_ex_copy_line()
13ea7f
   bwipe!
13ea7f
 endfunc
13ea7f
 
13ea7f
+" This was leaving the end of the Visual area beyond the end of a line.
13ea7f
+" Set 'undolevels' to start a new undo block.
13ea7f
+func Test_visual_undo_deletes_last_line()
13ea7f
+  new
13ea7f
+  call setline(1, ["aaa", "ccc", "dyd"])
13ea7f
+  set undolevels=100
13ea7f
+  exe "normal obbbbbbbbbxbb\<Esc>"
13ea7f
+  set undolevels=100
13ea7f
+  /y
13ea7f
+  exe "normal ggvjfxO"
13ea7f
+  undo
13ea7f
+  normal gNU
13ea7f
+  bwipe!
13ea7f
+endfunc
13ea7f
+
13ea7f
 
13ea7f
 " vim: shiftwidth=2 sts=2 expandtab
13ea7f
diff --git a/src/undo.c b/src/undo.c
13ea7f
index 4d186d453..636144aef 100644
13ea7f
--- a/src/undo.c
13ea7f
+++ b/src/undo.c
13ea7f
@@ -3029,6 +3029,8 @@ u_undo_end(
13ea7f
 	}
13ea7f
     }
13ea7f
 #endif
13ea7f
+    if (VIsual_active)
13ea7f
+	check_pos(curbuf, &VIsual);
13ea7f
 
13ea7f
     smsg_attr_keep(0, _("%ld %s; %s #%ld  %s"),
13ea7f
 	    u_oldcount < 0 ? -u_oldcount : u_oldcount,
13ea7f
-- 
13ea7f
2.34.1
13ea7f