]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1048: crash after scrolling and pasting in silent Ex mode v9.1.1048
authorzeertzjq <zeertzjq@outlook.com>
Wed, 22 Jan 2025 21:27:30 +0000 (22:27 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 22 Jan 2025 21:27:30 +0000 (22:27 +0100)
Problem:  Crash after scrolling and pasting in silent Ex mode.
          (fizz-is-on-the-way)
Solution: Don't move cursor to line 0 when scrolling.
          (zeertzjq)

closes: #16506

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/move.c
src/testdir/test_normal.vim
src/version.c

index f2780e584ec43f2e2081398bb21c8ab590f84766..ed252d9dbda9868b64a4b9d6e869478b26d4cca8 100644 (file)
@@ -3285,8 +3285,11 @@ pagescroll(int dir, long count, int half)
        {
            // Place cursor at top or bottom of window.
            validate_botline();
-           curwin->w_cursor.lnum = (dir == FORWARD ? curwin->w_topline
+           linenr_T lnum = (dir == FORWARD ? curwin->w_topline
                                                    : curwin->w_botline - 1);
+           // In silent Ex mode the value of w_botline - 1 may be 0,
+           // but cursor lnum needs to be at least 1.
+           curwin->w_cursor.lnum = MAX(lnum, 1);
        }
     }
 
index 6dd3fac0cdcd70315624b044de5c14bd01741a4e..75a3028b6df57ba02a10e1a87cce2341de2d88bd 100644 (file)
@@ -1342,6 +1342,22 @@ func Test_scroll_in_ex_mode()
   call delete('Xdone')
 endfunc
 
+func Test_scroll_and_paste_in_ex_mode()
+  " This used to crash because of moving cursor to line 0.
+  let lines =<< trim END
+      v/foo/vi|YY9PYQ
+      v/bar/vi|YY9PYQ
+      v/bar/exe line('.') == 1 ? "vi|Y\<C-B>9PYQ" : "vi|YQ"
+      call writefile(['done'], 'Xdone')
+      qa!
+  END
+  call writefile(lines, 'Xscript', 'D')
+  call assert_equal(1, RunVim([], [], '-u NONE -i NONE -n -X -Z -e -s -S Xscript'))
+  call assert_equal(['done'], readfile('Xdone'))
+
+  call delete('Xdone')
+endfunc
+
 " Test for the 'sidescroll' option
 func Test_sidescroll_opt()
   new
@@ -4293,4 +4309,5 @@ func Test_normal_go()
 
   bwipe!
 endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
index c9f88e93d920097fb42a59e669315bb9584c1f42..67f168903ebf51eebc9b78e00175fa43d27dd613 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1048,
 /**/
     1047,
 /**/