Skip to content

Commit b6f1480

Browse files
committed
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)
1 parent 9f84ded commit b6f1480

3 files changed

Lines changed: 74 additions & 34 deletions

File tree

src/quickfix.c

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,8 @@ qf_jump_edit_buffer(
29852985
{
29862986
qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
29872987
int retval = OK;
2988+
int old_qf_curlist = qi->qf_curlist;
2989+
int save_qfid = qfl->qf_id;
29882990

29892991
if (qf_ptr->qf_type == 1)
29902992
{
@@ -2993,46 +2995,40 @@ qf_jump_edit_buffer(
29932995
if (!can_abandon(curbuf, forceit))
29942996
{
29952997
no_write_message();
2996-
retval = FAIL;
2998+
return FAIL;
29972999
}
2998-
else
2999-
retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
3000-
ECMD_HIDE + ECMD_SET_HELP,
3001-
oldwin == curwin ? curwin : NULL);
3000+
3001+
retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
3002+
ECMD_HIDE + ECMD_SET_HELP,
3003+
oldwin == curwin ? curwin : NULL);
30023004
}
30033005
else
3004-
{
3005-
int old_qf_curlist = qi->qf_curlist;
3006-
int save_qfid = qfl->qf_id;
3007-
30083006
retval = buflist_getfile(qf_ptr->qf_fnum,
30093007
(linenr_T)1, GETF_SETMARK | GETF_SWITCH, forceit);
30103008

3011-
if (IS_LL_STACK(qi))
3012-
{
3013-
// Location list. Check whether the associated window is still
3014-
// present and the list is still valid.
3015-
if (!win_valid_any_tab(oldwin))
3016-
{
3017-
EMSG(_("E924: Current window was closed"));
3018-
*opened_window = FALSE;
3019-
return NOTDONE;
3020-
}
3021-
else if (!qflist_valid(oldwin, save_qfid))
3022-
{
3023-
EMSG(_(e_loc_list_changed));
3024-
return NOTDONE;
3025-
}
3026-
}
3027-
else if (old_qf_curlist != qi->qf_curlist
3028-
|| !is_qf_entry_present(qfl, qf_ptr))
3029-
{
3030-
if (IS_QF_STACK(qi))
3031-
EMSG(_("E925: Current quickfix was changed"));
3032-
else
3033-
EMSG(_(e_loc_list_changed));
3034-
return NOTDONE;
3035-
}
3009+
// If a location list, check whether the associated window is still
3010+
// present.
3011+
if (IS_LL_STACK(qi) && !win_valid_any_tab(oldwin))
3012+
{
3013+
EMSG(_("E924: Current window was closed"));
3014+
*opened_window = FALSE;
3015+
return NOTDONE;
3016+
}
3017+
3018+
if (IS_QF_STACK(qi) && !qflist_valid(NULL, save_qfid))
3019+
{
3020+
EMSG(_("E925: Current quickfix was changed"));
3021+
return NOTDONE;
3022+
}
3023+
3024+
if (old_qf_curlist != qi->qf_curlist
3025+
|| !is_qf_entry_present(qfl, qf_ptr))
3026+
{
3027+
if (IS_QF_STACK(qi))
3028+
EMSG(_("E925: Current quickfix was changed"));
3029+
else
3030+
EMSG(_(e_loc_list_changed));
3031+
return NOTDONE;
30363032
}
30373033

30383034
return retval;

src/testdir/test_quickfix.vim

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,17 @@ func Test_lvimgrep_crash()
32553255
augroup QF_Test
32563256
au!
32573257
augroup END
3258+
3259+
new | only
3260+
augroup QF_Test
3261+
au!
3262+
au BufEnter * call setloclist(0, [], 'r')
3263+
augroup END
3264+
call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3265+
augroup QF_Test
3266+
au!
3267+
augroup END
3268+
32583269
enew | only
32593270
endfunc
32603271

@@ -3337,6 +3348,37 @@ func Test_lhelpgrep_autocmd()
33373348
call assert_equal('help', &filetype)
33383349
call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
33393350
au! QuickFixCmdPost
3351+
3352+
new | only
3353+
augroup QF_Test
3354+
au!
3355+
au BufEnter * call setqflist([], 'f')
3356+
augroup END
3357+
call assert_fails('helpgrep quickfix', 'E925:')
3358+
augroup QF_Test
3359+
au! BufEnter
3360+
augroup END
3361+
3362+
new | only
3363+
augroup QF_Test
3364+
au!
3365+
au BufEnter * call setqflist([], 'r')
3366+
augroup END
3367+
call assert_fails('helpgrep quickfix', 'E925:')
3368+
augroup QF_Test
3369+
au! BufEnter
3370+
augroup END
3371+
3372+
new | only
3373+
augroup QF_Test
3374+
au!
3375+
au BufEnter * call setloclist(0, [], 'r')
3376+
augroup END
3377+
call assert_fails('lhelpgrep quickfix', 'E926:')
3378+
augroup QF_Test
3379+
au! BufEnter
3380+
augroup END
3381+
33403382
new | only
33413383
endfunc
33423384

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
489,
795797
/**/
796798
488,
797799
/**/

0 commit comments

Comments
 (0)