Skip to content

Commit ccfde4d

Browse files
committed
patch 9.0.0389: crash when 'tagfunc' closes the window
Problem: Crash when 'tagfunc' closes the window. Solution: Bail out when the window was closed.
1 parent 8894761 commit ccfde4d

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,3 +3324,5 @@ EXTERN char e_non_null_dict_required_for_argument_nr[]
33243324
EXTERN char e_non_null_list_required_for_argument_nr[]
33253325
INIT(= N_("E1298: Non-NULL List required for argument %d"));
33263326
#endif
3327+
EXTERN char e_window_unexpectedly_close_while_searching_for_tags[]
3328+
INIT(= N_("E1299: Window unexpectedly closed while searching for tags"));

src/tag.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ do_tag(
690690
max_num_matches = MAXCOL; // If less than max_num_matches
691691
// found: all matches found.
692692

693+
// A tag function may do anything, which may cause various
694+
// information to become invalid. At least check for the tagstack
695+
// to still be the same.
696+
if (tagstack != curwin->w_tagstack)
697+
{
698+
emsg(_(e_window_unexpectedly_close_while_searching_for_tags));
699+
FreeWild(new_num_matches, new_matches);
700+
break;
701+
}
702+
693703
// If there already were some matches for the same name, move them
694704
// to the start. Avoids that the order changes when using
695705
// ":tnext" and jumping to another file.

src/testdir/test_tagfunc.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,17 @@ func Test_tagfunc_wipes_buffer()
401401
set tagfunc=
402402
endfunc
403403

404+
func Test_tagfunc_closes_window()
405+
split any
406+
func MytagfuncClose(pat, flags, info)
407+
close
408+
return [{'name' : 'mytag', 'filename' : 'Xtest', 'cmd' : '1'}]
409+
endfunc
410+
set tagfunc=MytagfuncClose
411+
call assert_fails('tag xyz', 'E1299:')
412+
413+
set tagfunc=
414+
endfunc
415+
416+
404417
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
389,
706708
/**/
707709
388,
708710
/**/

0 commit comments

Comments
 (0)