0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.1.0489: crash when autocmd clears vimpgrep location list

Problem:    Crash when autocmd clears vimpgrep location list.
Solution:   Return from qf_jump_edit_buffer() early. (Yegappan Lakshmanan)
This commit is contained in:
Bram Moolenaar
2018-10-21 18:47:43 +02:00
parent 9f84ded38b
commit b6f1480a6a
3 changed files with 74 additions and 34 deletions

View File

@@ -2985,6 +2985,8 @@ qf_jump_edit_buffer(
{ {
qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist]; qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
int retval = OK; int retval = OK;
int old_qf_curlist = qi->qf_curlist;
int save_qfid = qfl->qf_id;
if (qf_ptr->qf_type == 1) if (qf_ptr->qf_type == 1)
{ {
@@ -2993,46 +2995,40 @@ qf_jump_edit_buffer(
if (!can_abandon(curbuf, forceit)) if (!can_abandon(curbuf, forceit))
{ {
no_write_message(); no_write_message();
retval = FAIL; return FAIL;
} }
else
retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
ECMD_HIDE + ECMD_SET_HELP, ECMD_HIDE + ECMD_SET_HELP,
oldwin == curwin ? curwin : NULL); oldwin == curwin ? curwin : NULL);
} }
else else
{
int old_qf_curlist = qi->qf_curlist;
int save_qfid = qfl->qf_id;
retval = buflist_getfile(qf_ptr->qf_fnum, retval = buflist_getfile(qf_ptr->qf_fnum,
(linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit); (linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
if (IS_LL_STACK(qi)) // If a location list, check whether the associated window is still
{ // present.
// Location list. Check whether the associated window is still if (IS_LL_STACK(qi) && !win_valid_any_tab(oldwin))
// present and the list is still valid. {
if (!win_valid_any_tab(oldwin)) EMSG(_("E924: Current window was closed"));
{ *opened_window = FALSE;
EMSG(_("E924: Current window was closed")); return NOTDONE;
*opened_window = FALSE; }
return NOTDONE;
} if (IS_QF_STACK(qi) && !qflist_valid(NULL, save_qfid))
else if (!qflist_valid(oldwin, save_qfid)) {
{ EMSG(_("E925: Current quickfix was changed"));
EMSG(_(e_loc_list_changed)); return NOTDONE;
return NOTDONE; }
}
} if (old_qf_curlist != qi->qf_curlist
else if (old_qf_curlist != qi->qf_curlist || !is_qf_entry_present(qfl, qf_ptr))
|| !is_qf_entry_present(qfl, qf_ptr)) {
{ if (IS_QF_STACK(qi))
if (IS_QF_STACK(qi)) EMSG(_("E925: Current quickfix was changed"));
EMSG(_("E925: Current quickfix was changed")); else
else EMSG(_(e_loc_list_changed));
EMSG(_(e_loc_list_changed)); return NOTDONE;
return NOTDONE;
}
} }
return retval; return retval;

View File

@@ -3255,6 +3255,17 @@ func Test_lvimgrep_crash()
augroup QF_Test augroup QF_Test
au! au!
augroup END augroup END
new | only
augroup QF_Test
au!
au BufEnter * call setloclist(0, [], 'r')
augroup END
call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
augroup QF_Test
au!
augroup END
enew | only enew | only
endfunc endfunc
@@ -3337,6 +3348,37 @@ func Test_lhelpgrep_autocmd()
call assert_equal('help', &filetype) call assert_equal('help', &filetype)
call assert_equal(1, getloclist(0, {'nr' : '$'}).nr) call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
au! QuickFixCmdPost au! QuickFixCmdPost
new | only
augroup QF_Test
au!
au BufEnter * call setqflist([], 'f')
augroup END
call assert_fails('helpgrep quickfix', 'E925:')
augroup QF_Test
au! BufEnter
augroup END
new | only
augroup QF_Test
au!
au BufEnter * call setqflist([], 'r')
augroup END
call assert_fails('helpgrep quickfix', 'E925:')
augroup QF_Test
au! BufEnter
augroup END
new | only
augroup QF_Test
au!
au BufEnter * call setloclist(0, [], 'r')
augroup END
call assert_fails('lhelpgrep quickfix', 'E926:')
augroup QF_Test
au! BufEnter
augroup END
new | only new | only
endfunc endfunc

View File

@@ -792,6 +792,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
489,
/**/ /**/
488, 488,
/**/ /**/