mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.0911: crash when opening a buffer for the cmdline window fails
Problem: Crash when opening a buffer for the cmdline window fails. (Chris
Barber)
Solution: Check do_ecmd() succeeds. Reset got_int if "q" was used at the
more prompt. (closes vim/vim#6211)
9b7cce28d5
Make code match latest Vim instead.
This commit is contained in:
parent
99f8d34c8a
commit
4ecea0e001
@ -4184,9 +4184,13 @@ void wipe_buffer(buf_T *buf, bool aucmd)
|
|||||||
/// @param bufnr Buffer to switch to, or 0 to create a new buffer.
|
/// @param bufnr Buffer to switch to, or 0 to create a new buffer.
|
||||||
///
|
///
|
||||||
/// @see curbufIsChanged()
|
/// @see curbufIsChanged()
|
||||||
void buf_open_scratch(handle_T bufnr, char *bufname)
|
///
|
||||||
|
/// @return FAIL for failure, OK otherwise
|
||||||
|
int buf_open_scratch(handle_T bufnr, char *bufname)
|
||||||
{
|
{
|
||||||
(void)do_ecmd((int)bufnr, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL);
|
if (do_ecmd((int)bufnr, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL) == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf);
|
||||||
(void)setfname(curbuf, bufname, NULL, true);
|
(void)setfname(curbuf, bufname, NULL, true);
|
||||||
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf);
|
||||||
@ -4194,4 +4198,5 @@ void buf_open_scratch(handle_T bufnr, char *bufname)
|
|||||||
set_option_value_give_err("bt", 0L, "nofile", OPT_LOCAL);
|
set_option_value_give_err("bt", 0L, "nofile", OPT_LOCAL);
|
||||||
set_option_value_give_err("swf", 0L, NULL, OPT_LOCAL);
|
set_option_value_give_err("swf", 0L, NULL, OPT_LOCAL);
|
||||||
RESET_BINDING(curwin);
|
RESET_BINDING(curwin);
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -4073,17 +4073,27 @@ static int open_cmdwin(void)
|
|||||||
ga_clear(&winsizes);
|
ga_clear(&winsizes);
|
||||||
return K_IGNORE;
|
return K_IGNORE;
|
||||||
}
|
}
|
||||||
|
// Don't let quitting the More prompt make this fail.
|
||||||
|
got_int = false;
|
||||||
|
|
||||||
|
// Set "cmdwin_type" before any autocommands may mess things up.
|
||||||
cmdwin_type = get_cmdline_type();
|
cmdwin_type = get_cmdline_type();
|
||||||
cmdwin_level = ccline.level;
|
cmdwin_level = ccline.level;
|
||||||
|
|
||||||
// Create empty command-line buffer.
|
// Create empty command-line buffer.
|
||||||
buf_open_scratch(0, _("[Command Line]"));
|
if (buf_open_scratch(0, _("[Command Line]")) == FAIL) {
|
||||||
|
// Some autocommand messed it up?
|
||||||
|
win_close(curwin, true, false);
|
||||||
|
ga_clear(&winsizes);
|
||||||
|
cmdwin_type = 0;
|
||||||
|
return Ctrl_C;
|
||||||
|
}
|
||||||
// Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer.
|
// Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer.
|
||||||
set_option_value_give_err("bh", 0L, "wipe", OPT_LOCAL);
|
set_option_value_give_err("bh", 0L, "wipe", OPT_LOCAL);
|
||||||
curwin->w_p_rl = cmdmsg_rl;
|
|
||||||
cmdmsg_rl = false;
|
|
||||||
curbuf->b_p_ma = true;
|
curbuf->b_p_ma = true;
|
||||||
curwin->w_p_fen = false;
|
curwin->w_p_fen = false;
|
||||||
|
curwin->w_p_rl = cmdmsg_rl;
|
||||||
|
cmdmsg_rl = false;
|
||||||
|
|
||||||
// Don't allow switching to another buffer.
|
// Don't allow switching to another buffer.
|
||||||
curbuf->b_ro_locked++;
|
curbuf->b_ro_locked++;
|
||||||
|
@ -1453,6 +1453,33 @@ func Test_cmdwin_tabpage()
|
|||||||
tabclose!
|
tabclose!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_cmdwin_interrupted()
|
||||||
|
CheckScreendump
|
||||||
|
|
||||||
|
" aborting the :smile output caused the cmdline window to use the current
|
||||||
|
" buffer.
|
||||||
|
let lines =<< trim [SCRIPT]
|
||||||
|
au WinNew * smile
|
||||||
|
[SCRIPT]
|
||||||
|
call writefile(lines, 'XTest_cmdwin')
|
||||||
|
|
||||||
|
let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
|
||||||
|
call TermWait(buf, 1000)
|
||||||
|
" open cmdwin
|
||||||
|
call term_sendkeys(buf, "q:")
|
||||||
|
call TermWait(buf, 500)
|
||||||
|
" quit more prompt for :smile command
|
||||||
|
call term_sendkeys(buf, "q")
|
||||||
|
call TermWait(buf, 500)
|
||||||
|
" execute a simple command
|
||||||
|
call term_sendkeys(buf, "aecho 'done'\<CR>")
|
||||||
|
call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
|
||||||
|
|
||||||
|
" clean up
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
call delete('XTest_cmdwin')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for backtick expression in the command line
|
" Test for backtick expression in the command line
|
||||||
func Test_cmd_backtick()
|
func Test_cmd_backtick()
|
||||||
CheckNotMSWindows " FIXME: see #19297
|
CheckNotMSWindows " FIXME: see #19297
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local helpers = require('test.functional.helpers')(after_each)
|
local helpers = require('test.functional.helpers')(after_each)
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
local clear = helpers.clear
|
local clear = helpers.clear
|
||||||
|
local command = helpers.command
|
||||||
local feed = helpers.feed
|
local feed = helpers.feed
|
||||||
local feed_command = helpers.feed_command
|
local feed_command = helpers.feed_command
|
||||||
local exec = helpers.exec
|
local exec = helpers.exec
|
||||||
@ -141,3 +142,81 @@ describe('cmdline', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('cmdwin', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
-- oldtest: Test_cmdwin_interrupted()
|
||||||
|
it('still uses a new buffer when interrupting more prompt on open', function()
|
||||||
|
local screen = Screen.new(30, 16)
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
|
||||||
|
[1] = {bold = true, reverse = true}, -- StatusLine
|
||||||
|
[2] = {reverse = true}, -- StatusLineNC
|
||||||
|
[3] = {bold = true, foreground = Screen.colors.SeaGreen}, -- MoreMsg
|
||||||
|
[4] = {bold = true}, -- ModeMsg
|
||||||
|
})
|
||||||
|
screen:attach()
|
||||||
|
command('set more')
|
||||||
|
command('autocmd WinNew * highlight')
|
||||||
|
feed('q:')
|
||||||
|
screen:expect({any = '{3:%-%- More %-%-}^'})
|
||||||
|
feed('q')
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
{0::}^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{1:[Command Line] }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
feed([[aecho 'done']])
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{2:[No Name] }|
|
||||||
|
{0::}echo 'done'^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{1:[Command Line] }|
|
||||||
|
{4:-- INSERT --} |
|
||||||
|
]])
|
||||||
|
feed('<CR>')
|
||||||
|
screen:expect([[
|
||||||
|
^ |
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
{0:~ }|
|
||||||
|
done |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user