Patch 9.0.0864
Problem: Crash when using "!!" without a previous shell command.
Solution: Check "prevcmd" is not NULL. (closes #11487)
Files: src/ex_cmds.c, src/testdir/test_shell.vim
*** ../vim-9.0.0863/src/ex_cmds.c 2022-11-08 21:39:59.937440725 +0000
--- src/ex_cmds.c 2022-11-12 16:31:58.799029300 +0000
***************
*** 859,864 ****
--- 859,879 ----
#endif
/*
+ * Check that "prevcmd" is not NULL. If it is NULL then give an error message
+ * and return FALSE.
+ */
+ static int
+ prevcmd_is_set(void)
+ {
+ if (prevcmd == NULL)
+ {
+ emsg(_(e_no_previous_command));
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ /*
* Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd"
* Bangs in the argument are replaced with the previously entered command.
* Remember the argument.
***************
*** 913,921 ****
len += (int)STRLEN(newcmd);
if (ins_prevcmd)
{
! if (prevcmd == NULL)
{
- emsg(_(e_no_previous_command));
vim_free(newcmd);
return;
}
--- 928,935 ----
len += (int)STRLEN(newcmd);
if (ins_prevcmd)
{
! if (!prevcmd_is_set())
{
vim_free(newcmd);
return;
}
***************
*** 971,976 ****
--- 985,993 ----
if (bangredo) // put cmd in redo buffer for ! command
{
+ if (!prevcmd_is_set())
+ goto theend;
+
// If % or # appears in the command, it must have been escaped.
// Reescape them, so that redoing them does not substitute them by the
// buffername.
***************
*** 1020,1025 ****
--- 1037,1044 ----
do_filter(line1, line2, eap, newcmd, do_in, do_out);
apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf);
}
+
+ theend:
if (free_newcmd)
vim_free(newcmd);
}
*** ../vim-9.0.0863/src/testdir/test_shell.vim 2022-10-22 07:54:22.951580569 +0100
--- src/testdir/test_shell.vim 2022-11-12 16:35:07.131148607 +0000
***************
*** 282,285 ****
--- 282,298 ----
let &shell = save_shell
endfunc
+ func Test_shell_no_prevcmd()
+ " this doesn't do anything, just check it doesn't crash
+ let after =<< trim END
+ exe "normal !!\<CR>"
+ call writefile([v:errmsg, 'done'], 'Xtestdone')
+ qall!
+ END
+ if RunVim([], after, '--clean')
+ call assert_equal(['E34: No previous command', 'done'], readfile('Xtestdone'))
+ endif
+ call delete('Xtestdone')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0863/src/version.c 2022-11-12 16:07:01.781944372 +0000
--- src/version.c 2022-11-12 16:28:26.658893301 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 864,
/**/
--
hundred-and-one symptoms of being an internet addict:
44. Your friends no longer send you e-mail...they just log on to your IRC
channel.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///