From b62cc36a600e2e1e5a1d1d484fef89898c847c4c Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 3 Sep 2016 16:43:53 +0200 Subject: [PATCH] patch 7.4.2313 Problem: Crash when deleting an augroup and listing an autocommand. (Dominique Pelle) Solution: Make sure deleted_augroup is valid. --- src/fileio.c | 23 +++++++++++++++-------- src/testdir/test_autocmd.vim | 9 +++++++++ src/version.c | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 6bf54526a..6d5ed19d1 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -7758,6 +7758,7 @@ static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */ */ static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) +/* use get_deleted_augroup() to get this */ static char_u *deleted_augroup = NULL; /* @@ -7790,6 +7791,14 @@ static event_T last_event; static int last_group; static int autocmd_blocked = 0; /* block all autocmds */ + static char_u * +get_deleted_augroup(void) +{ + if (deleted_augroup == NULL) + deleted_augroup = (char_u *)_("--Deleted--"); + return deleted_augroup; +} + /* * Show the autocommands for one AutoPat. */ @@ -7813,7 +7822,7 @@ show_autocmd(AutoPat *ap, event_T event) if (ap->group != AUGROUP_DEFAULT) { if (AUGROUP_NAME(ap->group) == NULL) - msg_puts_attr(deleted_augroup, hl_attr(HLF_E)); + msg_puts_attr(get_deleted_augroup(), hl_attr(HLF_E)); else msg_puts_attr(AUGROUP_NAME(ap->group), hl_attr(HLF_T)); msg_puts((char_u *)" "); @@ -8029,9 +8038,7 @@ au_del_group(char_u *name) vim_free(AUGROUP_NAME(i)); if (in_use) { - if (deleted_augroup == NULL) - deleted_augroup = (char_u *)_("--Deleted--"); - AUGROUP_NAME(i) = deleted_augroup; + AUGROUP_NAME(i) = get_deleted_augroup(); } else AUGROUP_NAME(i) = NULL; @@ -8048,7 +8055,7 @@ au_find_group(char_u *name) int i; for (i = 0; i < augroups.ga_len; ++i) - if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != deleted_augroup + if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != get_deleted_augroup() && STRCMP(AUGROUP_NAME(i), name) == 0) return i; return AUGROUP_ERROR; @@ -8116,7 +8123,7 @@ free_all_autocmds(void) for (i = 0; i < augroups.ga_len; ++i) { s = ((char_u **)(augroups.ga_data))[i]; - if (s != deleted_augroup) + if (s != get_deleted_augroup()) vim_free(s); } ga_clear(&augroups); @@ -9865,7 +9872,7 @@ get_augroup_name(expand_T *xp UNUSED, int idx) return (char_u *)"END"; if (idx >= augroups.ga_len) /* end of list */ return NULL; - if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == deleted_augroup) + if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == get_deleted_augroup()) /* skip deleted entries */ return (char_u *)""; return AUGROUP_NAME(idx); /* return a name */ @@ -9931,7 +9938,7 @@ get_event_name(expand_T *xp UNUSED, int idx) if (idx < augroups.ga_len) /* First list group names, if wanted */ { if (!include_groups || AUGROUP_NAME(idx) == NULL - || AUGROUP_NAME(idx) == deleted_augroup) + || AUGROUP_NAME(idx) == get_deleted_augroup()) return (char_u *)""; /* skip deleted entries */ return AUGROUP_NAME(idx); /* return a name */ } diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index 6db3bf76d..7d786c88c 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -183,3 +183,12 @@ func Test_augroup_warning() redir END call assert_true(match(res, "W19:") < 0) endfunc + +func Test_augroup_deleted() + " This caused a crash + augroup x + augroup! x + au VimEnter * echo + au VimEnter +endfunc + diff --git a/src/version.c b/src/version.c index df1de63e0..8c10a9413 100644 --- a/src/version.c +++ b/src/version.c @@ -763,6 +763,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2313, /**/ 2312, /**/ -- 2.50.1