vim-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)
b6f1480a6a
This commit is contained in:
erw7
2020-09-13 01:39:07 +09:00
parent 46f973edf0
commit 80eafef3bb
2 changed files with 65 additions and 21 deletions

View File

@@ -2702,43 +2702,45 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit,
qf_list_T *qfl = qf_get_curlist(qi);
qfltype_T qfl_type = qfl->qfl_type;
int retval = OK;
int old_qf_curlist = qi->qf_curlist;
unsigned save_qfid = qfl->qf_id;
if (qf_ptr->qf_type == 1) {
// Open help file (do_ecmd() will set b_help flag, readfile() will
// set b_p_ro flag).
if (!can_abandon(curbuf, forceit)) {
no_write_message();
retval = FAIL;
return FAIL;
} else {
retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
ECMD_HIDE + ECMD_SET_HELP,
oldwin == curwin ? curwin : NULL);
}
} else {
unsigned save_qfid = qfl->qf_id;
retval = buflist_getfile(qf_ptr->qf_fnum, (linenr_T)1,
GETF_SETMARK | GETF_SWITCH, forceit);
}
// If a location list, check whether the associated window is still
// present.
if (qfl_type == QFLT_LOCATION && !win_valid_any_tab(oldwin)) {
EMSG(_("E924: Current window was closed"));
*opened_window = false;
return NOTDONE;
}
if (qfl_type == QFLT_LOCATION) {
// Location list. Check whether the associated window is still
// present and the list is still valid.
if (!win_valid_any_tab(oldwin)) {
EMSG(_("E924: Current window was closed"));
*opened_window = false;
return NOTDONE;
} else if (!qflist_valid(oldwin, save_qfid)) {
EMSG(_(e_loc_list_changed));
return NOTDONE;
}
} else if (!is_qf_entry_present(qfl, qf_ptr)) {
if (qfl_type == QFLT_QUICKFIX) {
EMSG(_("E925: Current quickfix was changed"));
} else {
EMSG(_(e_loc_list_changed));
}
return NOTDONE;
if (qfl_type == QFLT_QUICKFIX && !qflist_valid(NULL, save_qfid)) {
EMSG(_("E925: Current quickfix was changed"));
return NOTDONE;
}
if (old_qf_curlist != qi->qf_curlist
|| !is_qf_entry_present(qfl, qf_ptr)) {
if (qfl_type == QFLT_QUICKFIX) {
EMSG(_("E925: Current quickfix was changed"));
} else {
EMSG(_(e_loc_list_changed));
}
return NOTDONE;
}
return retval;

View File

@@ -3342,6 +3342,17 @@ func Test_lvimgrep_crash()
augroup QF_Test
au!
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
endfunc
@@ -3432,6 +3443,37 @@ func Test_lhelpgrep_autocmd()
call assert_equal('help', &filetype)
call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
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
endfunc