]> granicus.if.org Git - vim/commitdiff
patch 8.2.0097: crash with autocommand and spellfile v8.2.0097
authorBram Moolenaar <Bram@vim.org>
Tue, 7 Jan 2020 19:11:42 +0000 (20:11 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 7 Jan 2020 19:11:42 +0000 (20:11 +0100)
Problem:    Crash with autocommand and spellfile. (Tim Pope)
Solution:   Do not pop exestack when not pushed. (closes #5450)

src/spellfile.c
src/testdir/test_autocmd.vim
src/version.c

index 6cad202fd3a6ac5f0c3b5b035d68c9263cdc5120..fa450f33ddeb14a07ad05942d39c5f0a1b6c1848 100644 (file)
@@ -352,6 +352,7 @@ spell_load_file(
     slang_T    *lp = NULL;
     int                c = 0;
     int                res;
+    int                did_estack_push = FALSE;
 
     fd = mch_fopen((char *)fname, "r");
     if (fd == NULL)
@@ -392,6 +393,7 @@ spell_load_file(
 
     // Set sourcing_name, so that error messages mention the file name.
     estack_push(ETYPE_SPELL, fname, 0);
+    did_estack_push = TRUE;
 
     /*
      * <HEADER>: <fileID>
@@ -578,7 +580,8 @@ endFAIL:
 endOK:
     if (fd != NULL)
        fclose(fd);
-    estack_pop();
+    if (did_estack_push)
+       estack_pop();
 
     return lp;
 }
index ab02402398be2c6dce508f0a3e3e092c87fe292e..23deec6c306425d5a6155b4d1a104d65ecdde133 100644 (file)
@@ -2335,3 +2335,25 @@ func Test_BufWrite_lockmarks()
   call delete('Xtest')
   call delete('Xtest2')
 endfunc
+
+func Test_FileType_spell()
+  if !isdirectory('/tmp')
+    throw "Skipped: requires /tmp directory"
+  endif
+
+  " this was crashing with an invalid free()
+  setglobal spellfile=/tmp/en.utf-8.add
+  augroup crash
+    autocmd!
+    autocmd BufNewFile,BufReadPost crashfile setf somefiletype
+    autocmd BufNewFile,BufReadPost crashfile set ft=anotherfiletype
+    autocmd FileType anotherfiletype setlocal spell
+  augroup END
+  func! NoCrash() abort
+    edit /tmp/crashfile
+  endfunc
+  call NoCrash()
+
+  au! crash
+  setglobal spellfile=
+endfunc
index f51df26c4bcf6fa99a479972cd98463e33303a67..b476e25a4c8274afba7680c903e77ff1d269a3f9 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    97,
 /**/
     96,
 /**/