vim-patch:9.0.1332: crash when using buffer-local user command in cmdline window (#22346)

Problem:    Crash when using buffer-local user command in cmdline window.
            (Karl Yngve Lervåg)
Solution:   Use the right buffer to find the user command. (closes vim/vim#12030,
            closes vim/vim#12029)

b444ee761a
This commit is contained in:
zeertzjq 2023-02-20 23:55:42 +08:00 committed by GitHub
parent 93c627b90b
commit 3507474611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -736,6 +736,15 @@ func Test_buflocal_ambiguous_usercmd()
bw! bw!
endfunc endfunc
" Test for using buffer-local user command from cmdwin.
func Test_buflocal_usercmd_cmdwin()
new
command -buffer TestCmd edit Test
" This used to crash Vim
call assert_fails("norm q::TestCmd\<CR>", 'E11:')
bw!
endfunc
" Test for using a multibyte character in a user command " Test for using a multibyte character in a user command
func Test_multibyte_in_usercmd() func Test_multibyte_in_usercmd()
command SubJapanesePeriodToDot exe "%s/\u3002/./g" command SubJapanesePeriodToDot exe "%s/\u3002/./g"

View File

@ -1625,7 +1625,7 @@ int do_ucmd(exarg_T *eap, bool preview)
if (eap->cmdidx == CMD_USER) { if (eap->cmdidx == CMD_USER) {
cmd = USER_CMD(eap->useridx); cmd = USER_CMD(eap->useridx);
} else { } else {
cmd = USER_CMD_GA(&curbuf->b_ucmds, eap->useridx); cmd = USER_CMD_GA(&prevwin_curwin()->w_buffer->b_ucmds, eap->useridx);
} }
if (preview) { if (preview) {