Skip to content

Commit b62cc36

Browse files
committed
patch 7.4.2313
Problem: Crash when deleting an augroup and listing an autocommand. (Dominique Pelle) Solution: Make sure deleted_augroup is valid.
1 parent 5a49789 commit b62cc36

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

src/fileio.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7758,6 +7758,7 @@ static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */
77587758
*/
77597759
static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL};
77607760
#define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
7761+
/* use get_deleted_augroup() to get this */
77617762
static char_u *deleted_augroup = NULL;
77627763

77637764
/*
@@ -7790,6 +7791,14 @@ static event_T last_event;
77907791
static int last_group;
77917792
static int autocmd_blocked = 0; /* block all autocmds */
77927793

7794+
static char_u *
7795+
get_deleted_augroup(void)
7796+
{
7797+
if (deleted_augroup == NULL)
7798+
deleted_augroup = (char_u *)_("--Deleted--");
7799+
return deleted_augroup;
7800+
}
7801+
77937802
/*
77947803
* Show the autocommands for one AutoPat.
77957804
*/
@@ -7813,7 +7822,7 @@ show_autocmd(AutoPat *ap, event_T event)
78137822
if (ap->group != AUGROUP_DEFAULT)
78147823
{
78157824
if (AUGROUP_NAME(ap->group) == NULL)
7816-
msg_puts_attr(deleted_augroup, hl_attr(HLF_E));
7825+
msg_puts_attr(get_deleted_augroup(), hl_attr(HLF_E));
78177826
else
78187827
msg_puts_attr(AUGROUP_NAME(ap->group), hl_attr(HLF_T));
78197828
msg_puts((char_u *)" ");
@@ -8029,9 +8038,7 @@ au_del_group(char_u *name)
80298038
vim_free(AUGROUP_NAME(i));
80308039
if (in_use)
80318040
{
8032-
if (deleted_augroup == NULL)
8033-
deleted_augroup = (char_u *)_("--Deleted--");
8034-
AUGROUP_NAME(i) = deleted_augroup;
8041+
AUGROUP_NAME(i) = get_deleted_augroup();
80358042
}
80368043
else
80378044
AUGROUP_NAME(i) = NULL;
@@ -8048,7 +8055,7 @@ au_find_group(char_u *name)
80488055
int i;
80498056

80508057
for (i = 0; i < augroups.ga_len; ++i)
8051-
if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != deleted_augroup
8058+
if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != get_deleted_augroup()
80528059
&& STRCMP(AUGROUP_NAME(i), name) == 0)
80538060
return i;
80548061
return AUGROUP_ERROR;
@@ -8116,7 +8123,7 @@ free_all_autocmds(void)
81168123
for (i = 0; i < augroups.ga_len; ++i)
81178124
{
81188125
s = ((char_u **)(augroups.ga_data))[i];
8119-
if (s != deleted_augroup)
8126+
if (s != get_deleted_augroup())
81208127
vim_free(s);
81218128
}
81228129
ga_clear(&augroups);
@@ -9865,7 +9872,7 @@ get_augroup_name(expand_T *xp UNUSED, int idx)
98659872
return (char_u *)"END";
98669873
if (idx >= augroups.ga_len) /* end of list */
98679874
return NULL;
9868-
if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == deleted_augroup)
9875+
if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == get_deleted_augroup())
98699876
/* skip deleted entries */
98709877
return (char_u *)"";
98719878
return AUGROUP_NAME(idx); /* return a name */
@@ -9931,7 +9938,7 @@ get_event_name(expand_T *xp UNUSED, int idx)
99319938
if (idx < augroups.ga_len) /* First list group names, if wanted */
99329939
{
99339940
if (!include_groups || AUGROUP_NAME(idx) == NULL
9934-
|| AUGROUP_NAME(idx) == deleted_augroup)
9941+
|| AUGROUP_NAME(idx) == get_deleted_augroup())
99359942
return (char_u *)""; /* skip deleted entries */
99369943
return AUGROUP_NAME(idx); /* return a name */
99379944
}

src/testdir/test_autocmd.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,12 @@ func Test_augroup_warning()
183183
redir END
184184
call assert_true(match(res, "W19:") < 0)
185185
endfunc
186+
187+
func Test_augroup_deleted()
188+
" This caused a crash
189+
augroup x
190+
augroup! x
191+
au VimEnter * echo
192+
au VimEnter
193+
endfunc
194+

src/version.c

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

764764
static int included_patches[] =
765765
{ /* Add new patch number below this line */
766+
/**/
767+
2313,
766768
/**/
767769
2312,
768770
/**/

0 commit comments

Comments
 (0)