vim-patch:9.0.0824: crash when using win_move_separator() in other tab page

Problem:    Crash when using win_move_separator() in other tab page.
Solution:   Check for valid window in current tab page.
            (closes vim/vim#11479, closes vim/vim#11427)

873f41a018
This commit is contained in:
zeertzjq
2022-11-01 20:22:48 +08:00
parent 20bd4d8997
commit 39f85cdf6b
3 changed files with 24 additions and 4 deletions

View File

@@ -9690,6 +9690,10 @@ static void f_win_move_separator(typval_T *argvars, typval_T *rettv, EvalFuncDat
if (wp == NULL || wp->w_floating) {
return;
}
if (!win_valid(wp)) {
emsg(_(e_cannot_resize_window_in_another_tab_page));
return;
}
int offset = (int)tv_get_number(&argvars[1]);
win_drag_vsep_line(wp, offset);

View File

@@ -1054,18 +1054,24 @@ func Test_mouse_drag_statusline()
set laststatus=2
set mouse=a
func ClickExpr()
call Ntest_setmouse(&lines - 1, 1)
return "\<LeftMouse>"
call Ntest_setmouse(&lines - 1, 1)
return "\<LeftMouse>"
endfunc
func DragExpr()
call Ntest_setmouse(&lines - 2, 1)
return "\<LeftDrag>"
call Ntest_setmouse(&lines - 2, 1)
return "\<LeftDrag>"
endfunc
nnoremap <expr> <F2> ClickExpr()
nnoremap <expr> <F3> DragExpr()
" this was causing a crash in win_drag_status_line()
call feedkeys("\<F2>:tabnew\<CR>\<F3>", 'tx')
nunmap <F2>
nunmap <F3>
delfunc ClickExpr
delfunc DragExpr
set laststatus& mouse&
endfunc
" Test for mapping <LeftDrag> in Insert mode

View File

@@ -1393,17 +1393,20 @@ func Test_win_move_separator()
call assert_equal(w0, winwidth(0))
call assert_true(win_move_separator(0, -1))
call assert_equal(w0, winwidth(0))
" check that win_move_separator doesn't error with offsets beyond moving
" possibility
call assert_true(win_move_separator(id, 5000))
call assert_true(winwidth(id) > w)
call assert_true(win_move_separator(id, -5000))
call assert_true(winwidth(id) < w)
" check that win_move_separator returns false for an invalid window
wincmd =
let w = winwidth(0)
call assert_false(win_move_separator(-1, 1))
call assert_equal(w, winwidth(0))
" check that win_move_separator returns false for a floating window
let id = nvim_open_win(
\ 0, 0, #{relative: 'editor', row: 2, col: 2, width: 5, height: 3})
@@ -1411,6 +1414,13 @@ func Test_win_move_separator()
call assert_false(win_move_separator(id, 1))
call assert_equal(w, winwidth(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_separator(id, -1)', 'E1308:')
tabclose
%bwipe!
endfunc