From 4152151c94d1d0e4749ad347ee799834498dea49 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 1 Nov 2022 06:45:55 +0800 Subject: [PATCH] vim-patch:9.0.0821: crash with win_move_statusline() in another tabpage vim-patch:86e6717ace4f Problem: Crash when using win_move_statusline() in another tab page. Solution: Check for valid window pointer. (issue vim/vim#11427) https://github.com/vim/vim/commit/86e6717ace4f5e00eaeb84b59e3fc92bca548155 Co-authored-by: Bram Moolenaar (cherry picked from commit d2a22242fbcb001571dbb285542ec8f776aa758c) --- src/nvim/eval/funcs.c | 6 ++++++ src/nvim/testdir/test_window_cmd.vim | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f2ef8e5cdd..bc2b6f0670 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -113,6 +113,8 @@ PRAGMA_DIAG_POP static char *e_listblobarg = N_("E899: Argument of %s must be a List or Blob"); static char *e_invalwindow = N_("E957: Invalid window number"); static char *e_reduceempty = N_("E998: Reduce of an empty %s with no initial value"); +static char e_cannot_resize_window_in_another_tab_page[] + = N_("E1308: Cannot resize a window in another tab page"); /// Dummy va_list for passing to vim_snprintf /// @@ -9704,6 +9706,10 @@ static void f_win_move_statusline(typval_T *argvars, typval_T *rettv, EvalFuncDa if (wp == NULL || wp->w_floating) { return; } + if (!win_valid(wp)) { + emsg(_(e_cannot_resize_window_in_another_tab_page)); + return; + } offset = (int)tv_get_number(&argvars[1]); win_drag_status_line(wp, offset); diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index b64f44360b..aebc3bf2f3 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -1451,17 +1451,20 @@ func Test_win_move_statusline() call assert_true(id->win_move_statusline(-offset)) call assert_equal(h, winheight(id)) endfor + " check that win_move_statusline doesn't error with offsets beyond moving " possibility call assert_true(win_move_statusline(id, 5000)) call assert_true(winheight(id) > h) call assert_true(win_move_statusline(id, -5000)) call assert_true(winheight(id) < h) + " check that win_move_statusline returns false for an invalid window wincmd = let h = winheight(0) call assert_false(win_move_statusline(-1, 1)) call assert_equal(h, winheight(0)) + " check that win_move_statusline returns false for a floating window let id = nvim_open_win( \ 0, 0, #{relative: 'editor', row: 2, col: 2, width: 5, height: 3}) @@ -1469,6 +1472,13 @@ func Test_win_move_statusline() call assert_false(win_move_statusline(id, 1)) call assert_equal(h, winheight(id)) call nvim_win_close(id, 1) + + " check that using another tabpage fails without crash + let id = win_getid() + tabnew + call assert_fails('call win_move_statusline(id, -1)', 'E1308:') + tabclose + %bwipe! endfunc