comparison src/fileio.c @ 10084:3e410e6e1986 v7.4.2313

commit https://github.com/vim/vim/commit/b62cc36a600e2e1e5a1d1d484fef89898c847c4c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 3 16:43:53 2016 +0200 patch 7.4.2313 Problem: Crash when deleting an augroup and listing an autocommand. (Dominique Pelle) Solution: Make sure deleted_augroup is valid.
author Christian Brabandt <cb@256bit.org>
date Sat, 03 Sep 2016 16:45:06 +0200
parents 65e43481d7de
children 1de911ef1edf
comparison
equal deleted inserted replaced
10083:00694b6618b0 10084:3e410e6e1986
7756 /* 7756 /*
7757 * augroups stores a list of autocmd group names. 7757 * augroups stores a list of autocmd group names.
7758 */ 7758 */
7759 static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL}; 7759 static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL};
7760 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i]) 7760 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
7761 /* use get_deleted_augroup() to get this */
7761 static char_u *deleted_augroup = NULL; 7762 static char_u *deleted_augroup = NULL;
7762 7763
7763 /* 7764 /*
7764 * The ID of the current group. Group 0 is the default one. 7765 * The ID of the current group. Group 0 is the default one.
7765 */ 7766 */
7788 7789
7789 static event_T last_event; 7790 static event_T last_event;
7790 static int last_group; 7791 static int last_group;
7791 static int autocmd_blocked = 0; /* block all autocmds */ 7792 static int autocmd_blocked = 0; /* block all autocmds */
7792 7793
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
7793 /* 7802 /*
7794 * Show the autocommands for one AutoPat. 7803 * Show the autocommands for one AutoPat.
7795 */ 7804 */
7796 static void 7805 static void
7797 show_autocmd(AutoPat *ap, event_T event) 7806 show_autocmd(AutoPat *ap, event_T event)
7811 if (event != last_event || ap->group != last_group) 7820 if (event != last_event || ap->group != last_group)
7812 { 7821 {
7813 if (ap->group != AUGROUP_DEFAULT) 7822 if (ap->group != AUGROUP_DEFAULT)
7814 { 7823 {
7815 if (AUGROUP_NAME(ap->group) == NULL) 7824 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));
7817 else 7826 else
7818 msg_puts_attr(AUGROUP_NAME(ap->group), hl_attr(HLF_T)); 7827 msg_puts_attr(AUGROUP_NAME(ap->group), hl_attr(HLF_T));
7819 msg_puts((char_u *)" "); 7828 msg_puts((char_u *)" ");
7820 } 7829 }
7821 msg_puts_attr(event_nr2name(event), hl_attr(HLF_T)); 7830 msg_puts_attr(event_nr2name(event), hl_attr(HLF_T));
8027 } 8036 }
8028 } 8037 }
8029 vim_free(AUGROUP_NAME(i)); 8038 vim_free(AUGROUP_NAME(i));
8030 if (in_use) 8039 if (in_use)
8031 { 8040 {
8032 if (deleted_augroup == NULL) 8041 AUGROUP_NAME(i) = get_deleted_augroup();
8033 deleted_augroup = (char_u *)_("--Deleted--");
8034 AUGROUP_NAME(i) = deleted_augroup;
8035 } 8042 }
8036 else 8043 else
8037 AUGROUP_NAME(i) = NULL; 8044 AUGROUP_NAME(i) = NULL;
8038 } 8045 }
8039 } 8046 }
8046 au_find_group(char_u *name) 8053 au_find_group(char_u *name)
8047 { 8054 {
8048 int i; 8055 int i;
8049 8056
8050 for (i = 0; i < augroups.ga_len; ++i) 8057 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()
8052 && STRCMP(AUGROUP_NAME(i), name) == 0) 8059 && STRCMP(AUGROUP_NAME(i), name) == 0)
8053 return i; 8060 return i;
8054 return AUGROUP_ERROR; 8061 return AUGROUP_ERROR;
8055 } 8062 }
8056 8063
8114 do_autocmd((char_u *)"", TRUE); 8121 do_autocmd((char_u *)"", TRUE);
8115 8122
8116 for (i = 0; i < augroups.ga_len; ++i) 8123 for (i = 0; i < augroups.ga_len; ++i)
8117 { 8124 {
8118 s = ((char_u **)(augroups.ga_data))[i]; 8125 s = ((char_u **)(augroups.ga_data))[i];
8119 if (s != deleted_augroup) 8126 if (s != get_deleted_augroup())
8120 vim_free(s); 8127 vim_free(s);
8121 } 8128 }
8122 ga_clear(&augroups); 8129 ga_clear(&augroups);
8123 } 8130 }
8124 #endif 8131 #endif
9863 { 9870 {
9864 if (idx == augroups.ga_len) /* add "END" add the end */ 9871 if (idx == augroups.ga_len) /* add "END" add the end */
9865 return (char_u *)"END"; 9872 return (char_u *)"END";
9866 if (idx >= augroups.ga_len) /* end of list */ 9873 if (idx >= augroups.ga_len) /* end of list */
9867 return NULL; 9874 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())
9869 /* skip deleted entries */ 9876 /* skip deleted entries */
9870 return (char_u *)""; 9877 return (char_u *)"";
9871 return AUGROUP_NAME(idx); /* return a name */ 9878 return AUGROUP_NAME(idx); /* return a name */
9872 } 9879 }
9873 9880
9929 get_event_name(expand_T *xp UNUSED, int idx) 9936 get_event_name(expand_T *xp UNUSED, int idx)
9930 { 9937 {
9931 if (idx < augroups.ga_len) /* First list group names, if wanted */ 9938 if (idx < augroups.ga_len) /* First list group names, if wanted */
9932 { 9939 {
9933 if (!include_groups || AUGROUP_NAME(idx) == NULL 9940 if (!include_groups || AUGROUP_NAME(idx) == NULL
9934 || AUGROUP_NAME(idx) == deleted_augroup) 9941 || AUGROUP_NAME(idx) == get_deleted_augroup())
9935 return (char_u *)""; /* skip deleted entries */ 9942 return (char_u *)""; /* skip deleted entries */
9936 return AUGROUP_NAME(idx); /* return a name */ 9943 return AUGROUP_NAME(idx); /* return a name */
9937 } 9944 }
9938 return (char_u *)event_names[idx - augroups.ga_len].name; 9945 return (char_u *)event_names[idx - augroups.ga_len].name;
9939 } 9946 }