Patch 8.2.2386
Problem: Vim9: crash when using ":silent! put".
Solution: When ignoring an error for ":silent!" rewind the stack and skip
ahead to restoring the cmdmod. (closes #7717)
Files: src/vim9execute.c, src/testdir/test_vim9_func.vim
*** ../vim-8.2.2385/src/vim9execute.c 2021-01-21 13:03:01.618038875 +0100
--- src/vim9execute.c 2021-01-21 19:40:22.738092151 +0100
***************
*** 1124,1129 ****
--- 1124,1130 ----
msglist_T *private_msg_list = NULL;
cmdmod_T save_cmdmod;
int restore_cmdmod = FALSE;
+ int restore_cmdmod_stacklen = 0;
int save_emsg_silent_def = emsg_silent_def;
int save_did_emsg_def = did_emsg_def;
int trylevel_at_start = trylevel;
***************
*** 3398,3403 ****
--- 3399,3405 ----
case ISN_CMDMOD:
save_cmdmod = cmdmod;
restore_cmdmod = TRUE;
+ restore_cmdmod_stacklen = ectx.ec_stack.ga_len;
cmdmod = *iptr->isn_arg.cmdmod.cf_cmdmod;
apply_cmdmod(&cmdmod);
break;
***************
*** 3523,3529 ****
--- 3525,3546 ----
// when calling the function.
if (did_emsg_cumul + did_emsg == did_emsg_before
&& emsg_silent && did_emsg_def == 0)
+ {
+ // If a sequence of instructions causes an error while ":silent!"
+ // was used, restore the stack length and jump ahead to restoring
+ // the cmdmod.
+ if (restore_cmdmod)
+ {
+ while (ectx.ec_stack.ga_len > restore_cmdmod_stacklen)
+ {
+ --ectx.ec_stack.ga_len;
+ clear_tv(STACK_TV_BOT(0));
+ }
+ while (ectx.ec_instr[ectx.ec_iidx].isn_type != ISN_CMDMOD_REV)
+ ++ectx.ec_iidx;
+ }
continue;
+ }
on_fatal_error:
// Jump here for an error that messes up the stack.
// If we are not inside a try-catch started here, abort execution.
*** ../vim-8.2.2385/src/testdir/test_vim9_func.vim 2021-01-16 18:09:48.017277750 +0100
--- src/testdir/test_vim9_func.vim 2021-01-21 19:38:07.486444612 +0100
***************
*** 2184,2189 ****
--- 2184,2207 ----
CheckScriptSuccess(lines)
enddef
+ def Test_skip_cmds_with_silent()
+ var lines =<< trim END
+ vim9script
+
+ def Func(b: bool)
+ Crash()
+ enddef
+
+ def Crash()
+ sil! :/not found/d _
+ sil! :/not found/put _
+ enddef
+
+ Func(true)
+ END
+ CheckScriptSuccess(lines)
+ enddef
+
def Test_opfunc()
nnoremap <F3> <cmd>set opfunc=Opfunc<cr>g@
def g:Opfunc(_: any): string
*** ../vim-8.2.2385/src/version.c 2021-01-21 17:03:04.475217089 +0100
--- src/version.c 2021-01-21 19:35:04.066929476 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2386,
/**/
--
hundred-and-one symptoms of being an internet addict:
201. When somebody asks you where you are, you tell them in which chat room.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///