From d6607dae41ed783fe073a2d340a1d1b74adafa4d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 12 Dec 2025 23:55:49 -0500 Subject: [PATCH] vim-patch:8.2.1939: invalid memory access in Ex mode with global command Problem: Invalid memory access in Ex mode with global command. Solution: Make sure the cursor is on a valid line. (closes vim/vim#7238) https://github.com/vim/vim/commit/3b6d57f2ce87dc5a4b1a50e1b0fd2aeaf72faae2 Co-authored-by: Bram Moolenaar --- src/nvim/move.c | 1 + test/old/testdir/test_ex_mode.vim | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/nvim/move.c b/src/nvim/move.c index 762f6b7d51..20fdf3d649 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -259,6 +259,7 @@ void update_topline(win_T *wp) // If there is no valid screen and when the window height is zero just use // the cursor line. if (!default_grid.chars || wp->w_view_height == 0) { + check_cursor_lnum(wp); wp->w_topline = wp->w_cursor.lnum; wp->w_botline = wp->w_topline; wp->w_viewport_invalid = true; diff --git a/test/old/testdir/test_ex_mode.vim b/test/old/testdir/test_ex_mode.vim index cfe1552f29..c15bb4d1fe 100644 --- a/test/old/testdir/test_ex_mode.vim +++ b/test/old/testdir/test_ex_mode.vim @@ -259,6 +259,30 @@ func Test_ex_mode_errors() quit endfunc +func Test_ex_mode_with_global() + CheckFeature timers + + " This will get stuck in Normal mode after the failed "J", use a timer to + " get going again. + let lines =<< trim END + " call ch_logfile('logfile', 'w') + pedit + func FeedQ(id) + call feedkeys('gQ', 't') + endfunc + call timer_start(10, 'FeedQ') + g/^/vi|HJ + call writefile(['done'], 'Xdidexmode') + qall! + END + call writefile(lines, 'Xexmodescript') + call assert_equal(1, RunVim([], [], '-e -s -S Xexmodescript')) + call assert_equal(['done'], readfile('Xdidexmode')) + + call delete('Xdidexmode') + call delete('Xexmodescript') +endfunc + func Test_ex_mode_count_overflow() " The multiplication causes an integer overflow CheckNotAsan