comparison src/ex_cmds.c @ 23861:5d11a15dbaa9 v8.2.2472

patch 8.2.2472: crash when using command line window in an autocommand Commit: https://github.com/vim/vim/commit/aad5f9d79a2b71e9d2581eace3652be156102b9d Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 6 17:30:31 2021 +0100 patch 8.2.2472: crash when using command line window in an autocommand Problem: Crash when using command line window in an autocommand. (houyunsong) Solution: Save and restore au_new_curbuf.
author Bram Moolenaar <Bram@vim.org>
date Sat, 06 Feb 2021 17:45:03 +0100
parents 7517eb94239b
children ea2b697ddea8
comparison
equal deleted inserted replaced
23860:a8e6303f7da7 23861:5d11a15dbaa9
2708 * If the current buffer was empty and has no file name, curbuf 2708 * If the current buffer was empty and has no file name, curbuf
2709 * is returned by buflist_new(), nothing to do here. 2709 * is returned by buflist_new(), nothing to do here.
2710 */ 2710 */
2711 if (buf != curbuf) 2711 if (buf != curbuf)
2712 { 2712 {
2713 bufref_T save_au_new_curbuf;
2713 #ifdef FEAT_CMDWIN 2714 #ifdef FEAT_CMDWIN
2714 int save_cmdwin_type = cmdwin_type; 2715 int save_cmdwin_type = cmdwin_type;
2715 2716
2716 // BufLeave applies to the old buffer. 2717 // BufLeave applies to the old buffer.
2717 cmdwin_type = 0; 2718 cmdwin_type = 0;
2718 #endif 2719 #endif
2719 /* 2720 /*
2726 * - If we ended up in the new buffer already, need to skip a few 2727 * - If we ended up in the new buffer already, need to skip a few
2727 * things, set auto_buf. 2728 * things, set auto_buf.
2728 */ 2729 */
2729 if (buf->b_fname != NULL) 2730 if (buf->b_fname != NULL)
2730 new_name = vim_strsave(buf->b_fname); 2731 new_name = vim_strsave(buf->b_fname);
2732 save_au_new_curbuf = au_new_curbuf;
2731 set_bufref(&au_new_curbuf, buf); 2733 set_bufref(&au_new_curbuf, buf);
2732 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); 2734 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
2733 #ifdef FEAT_CMDWIN 2735 #ifdef FEAT_CMDWIN
2734 cmdwin_type = save_cmdwin_type; 2736 cmdwin_type = save_cmdwin_type;
2735 #endif 2737 #endif
2736 if (!bufref_valid(&au_new_curbuf)) 2738 if (!bufref_valid(&au_new_curbuf))
2737 { 2739 {
2738 // new buffer has been deleted 2740 // new buffer has been deleted
2739 delbuf_msg(new_name); // frees new_name 2741 delbuf_msg(new_name); // frees new_name
2742 au_new_curbuf = save_au_new_curbuf;
2740 goto theend; 2743 goto theend;
2741 } 2744 }
2742 #ifdef FEAT_EVAL 2745 #ifdef FEAT_EVAL
2743 if (aborting()) // autocmds may abort script processing 2746 if (aborting()) // autocmds may abort script processing
2744 { 2747 {
2745 vim_free(new_name); 2748 vim_free(new_name);
2749 au_new_curbuf = save_au_new_curbuf;
2746 goto theend; 2750 goto theend;
2747 } 2751 }
2748 #endif 2752 #endif
2749 if (buf == curbuf) // already in new buffer 2753 if (buf == curbuf) // already in new buffer
2750 auto_buf = TRUE; 2754 auto_buf = TRUE;
2776 #ifdef FEAT_EVAL 2780 #ifdef FEAT_EVAL
2777 // autocmds may abort script processing 2781 // autocmds may abort script processing
2778 if (aborting() && curwin->w_buffer != NULL) 2782 if (aborting() && curwin->w_buffer != NULL)
2779 { 2783 {
2780 vim_free(new_name); 2784 vim_free(new_name);
2785 au_new_curbuf = save_au_new_curbuf;
2781 goto theend; 2786 goto theend;
2782 } 2787 }
2783 #endif 2788 #endif
2784 // Be careful again, like above. 2789 // Be careful again, like above.
2785 if (!bufref_valid(&au_new_curbuf)) 2790 if (!bufref_valid(&au_new_curbuf))
2786 { 2791 {
2787 // new buffer has been deleted 2792 // new buffer has been deleted
2788 delbuf_msg(new_name); // frees new_name 2793 delbuf_msg(new_name); // frees new_name
2794 au_new_curbuf = save_au_new_curbuf;
2789 goto theend; 2795 goto theend;
2790 } 2796 }
2791 if (buf == curbuf) // already in new buffer 2797 if (buf == curbuf) // already in new buffer
2792 { 2798 {
2793 // close_buffer() has decremented the window count, 2799 // close_buffer() has decremented the window count,
2829 #ifdef FEAT_SPELL 2835 #ifdef FEAT_SPELL
2830 did_get_winopts = TRUE; 2836 did_get_winopts = TRUE;
2831 #endif 2837 #endif
2832 } 2838 }
2833 vim_free(new_name); 2839 vim_free(new_name);
2834 au_new_curbuf.br_buf = NULL; 2840 au_new_curbuf = save_au_new_curbuf;
2835 au_new_curbuf.br_buf_free_count = 0;
2836 } 2841 }
2837 2842
2838 curwin->w_pcmark.lnum = 1; 2843 curwin->w_pcmark.lnum = 1;
2839 curwin->w_pcmark.col = 0; 2844 curwin->w_pcmark.col = 0;
2840 } 2845 }