To: vim-dev@vim.org Subject: patch 5.5.017 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.5.017 Problem: If an error occurs when closing the current window, Vim could get stuck in the error handling. Solution: Don't set curwin to NULL when closing the current window. Files: src/window.c *** ../vim-5.5.16/src/window.c Wed Sep 22 10:06:19 1999 --- src/window.c Mon Oct 4 11:29:09 1999 *************** *** 17,22 **** --- 17,23 ---- static void win_exchange __ARGS((long)); static void win_rotate __ARGS((int, int)); static void win_goto __ARGS((WIN *wp)); + static void win_enter_ext __ARGS((WIN *wp, int undo_sync, int no_curwin)); static void win_append __ARGS((WIN *, WIN *)); static void win_remove __ARGS((WIN *)); static void win_new_height __ARGS((WIN *, int)); *************** *** 871,876 **** --- 872,878 ---- #ifdef AUTOCMD int other_buffer = FALSE; #endif + int close_curwin = FALSE; if (lastwin == firstwin) { *************** *** 932,944 **** win_new_height(wp, wp->w_height + win->w_height + win->w_status_height); win_free(win); if (win == curwin) ! curwin = NULL; if (p_ea) win_equal(wp, FALSE); ! if (curwin == NULL) { ! win_enter(wp, FALSE); #ifdef AUTOCMD if (other_buffer) /* careful: after this wp and win may be invalid! */ --- 934,952 ---- win_new_height(wp, wp->w_height + win->w_height + win->w_status_height); win_free(win); + + /* Make sure curwin isn't invalid. It can cause severe trouble when + * printing an error message. */ if (win == curwin) ! { ! curwin = wp; ! close_curwin = TRUE; ! } if (p_ea) win_equal(wp, FALSE); ! if (close_curwin) { ! win_enter_ext(wp, FALSE, TRUE); #ifdef AUTOCMD if (other_buffer) /* careful: after this wp and win may be invalid! */ *************** *** 1106,1127 **** /* * Make window wp the current window. - * Can be called when curwin == NULL, if curwin already has been closed. */ void win_enter(wp, undo_sync) ! WIN *wp; ! int undo_sync; { #ifdef AUTOCMD int other_buffer = FALSE; #endif ! if (wp == curwin) /* nothing to do */ return; #ifdef AUTOCMD ! if (curwin != NULL) { /* * Be careful: If autocommands delete the window, return now. --- 1114,1148 ---- /* * Make window wp the current window. */ void win_enter(wp, undo_sync) ! WIN *wp; ! int undo_sync; ! { ! win_enter_ext(wp, undo_sync, FALSE); ! } ! ! /* ! * Make window wp the current window. ! * Can be called with "curwin_invalid" TRUE, which means that curwin has just ! * been closed and isn't valid. ! */ ! static void ! win_enter_ext(wp, undo_sync, curwin_invalid) ! WIN *wp; ! int undo_sync; ! int curwin_invalid; { #ifdef AUTOCMD int other_buffer = FALSE; #endif ! if (wp == curwin && !curwin_invalid) /* nothing to do */ return; #ifdef AUTOCMD ! if (!curwin_invalid) { /* * Be careful: If autocommands delete the window, return now. *************** *** 1145,1151 **** /* may have to copy the buffer options when 'cpo' contains 'S' */ if (wp->w_buffer != curbuf) buf_copy_options(curbuf, wp->w_buffer, BCO_ENTER | BCO_NOHELP); ! if (curwin != NULL) { prevwin = curwin; /* remember for CTRL-W p */ curwin->w_redr_status = TRUE; --- 1166,1172 ---- /* may have to copy the buffer options when 'cpo' contains 'S' */ if (wp->w_buffer != curbuf) buf_copy_options(curbuf, wp->w_buffer, BCO_ENTER | BCO_NOHELP); ! if (!curwin_invalid) { prevwin = curwin; /* remember for CTRL-W p */ curwin->w_redr_status = TRUE; *** ../vim-5.5.16/src/version.c Mon Oct 4 11:25:03 1999 --- src/version.c Mon Oct 4 11:24:44 1999 *************** *** 420,420 **** --- 420,421 ---- { /* Add new patch number below this line */ + 17, -- ARTHUR: (as the MAN next to him is squashed by a sheep) Knights! Run away! Midst echoing shouts of "run away" the KNIGHTS retreat to cover with the odd cow or goose hitting them still. The KNIGHTS crouch down under cover. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /