Patch 8.2.2472
Problem: Crash when using command line window in an autocommand.
(houyunsong)
Solution: Save and restore au_new_curbuf.
Files: src/ex_cmds.c, src/testdir/test_autocmd.vim
*** ../vim-8.2.2471/src/ex_cmds.c 2021-02-03 21:56:53.499701546 +0100
--- src/ex_cmds.c 2021-02-06 17:23:33.627696783 +0100
***************
*** 2710,2717 ****
*/
if (buf != curbuf)
{
#ifdef FEAT_CMDWIN
! int save_cmdwin_type = cmdwin_type;
// BufLeave applies to the old buffer.
cmdwin_type = 0;
--- 2710,2718 ----
*/
if (buf != curbuf)
{
+ bufref_T save_au_new_curbuf;
#ifdef FEAT_CMDWIN
! int save_cmdwin_type = cmdwin_type;
// BufLeave applies to the old buffer.
cmdwin_type = 0;
***************
*** 2728,2733 ****
--- 2729,2735 ----
*/
if (buf->b_fname != NULL)
new_name = vim_strsave(buf->b_fname);
+ save_au_new_curbuf = au_new_curbuf;
set_bufref(&au_new_curbuf, buf);
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
#ifdef FEAT_CMDWIN
***************
*** 2737,2748 ****
--- 2739,2752 ----
{
// new buffer has been deleted
delbuf_msg(new_name); // frees new_name
+ au_new_curbuf = save_au_new_curbuf;
goto theend;
}
#ifdef FEAT_EVAL
if (aborting()) // autocmds may abort script processing
{
vim_free(new_name);
+ au_new_curbuf = save_au_new_curbuf;
goto theend;
}
#endif
***************
*** 2778,2783 ****
--- 2782,2788 ----
if (aborting() && curwin->w_buffer != NULL)
{
vim_free(new_name);
+ au_new_curbuf = save_au_new_curbuf;
goto theend;
}
#endif
***************
*** 2786,2791 ****
--- 2791,2797 ----
{
// new buffer has been deleted
delbuf_msg(new_name); // frees new_name
+ au_new_curbuf = save_au_new_curbuf;
goto theend;
}
if (buf == curbuf) // already in new buffer
***************
*** 2831,2838 ****
#endif
}
vim_free(new_name);
! au_new_curbuf.br_buf = NULL;
! au_new_curbuf.br_buf_free_count = 0;
}
curwin->w_pcmark.lnum = 1;
--- 2837,2843 ----
#endif
}
vim_free(new_name);
! au_new_curbuf = save_au_new_curbuf;
}
curwin->w_pcmark.lnum = 1;
*** ../vim-8.2.2471/src/testdir/test_autocmd.vim 2021-02-03 23:04:42.526462751 +0100
--- src/testdir/test_autocmd.vim 2021-02-06 17:28:50.666708628 +0100
***************
*** 2739,2747 ****
au BufNew,BufWinLeave * e %e
file yyy
au BufNew,BufWinLeave * ball
! call assert_fails('n xxx', 'E143:')
! bwipe %
au! BufNew
au! BufWinLeave
endfunc
--- 2739,2747 ----
au BufNew,BufWinLeave * e %e
file yyy
au BufNew,BufWinLeave * ball
! n xxx
! %bwipe
au! BufNew
au! BufWinLeave
endfunc
***************
*** 2758,2762 ****
--- 2758,2777 ----
au!
augroup END
endfunc
+
+ " Fuzzer found some strange combination that caused a crash.
+ func Test_autocmd_normal_mess()
+ augroup aucmd_normal_test
+ au BufLeave,BufWinLeave,BufHidden,BufUnload,BufDelete,BufWipeout * norm 7q/qc
+ augroup END
+ o4
+ silent! H
+ e xx
+ normal G
+
+ augroup aucmd_normal_test
+ au!
+ augroup END
+ endfunc
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.2471/src/version.c 2021-02-06 14:59:21.126120022 +0100
--- src/version.c 2021-02-06 16:57:40.088433147 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2472,
/**/
--
"Shoot for the moon. Even if you miss, you'll land among the stars."
/// 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 ///