changeset 28594:294771aab3ae v8.2.4821

patch 8.2.4821: crash when imported autoload script was deleted Commit: https://github.com/vim/vim/commit/aac12daa61d9e84616771ec9242fd232f46786e6 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 24 21:33:20 2022 +0100 patch 8.2.4821: crash when imported autoload script was deleted Problem: Crash when imported autoload script was deleted. Solution: Initialize local variable. (closes https://github.com/vim/vim/issues/10274) Give a more meaningful error message.
author Bram Moolenaar <Bram@vim.org>
date Sun, 24 Apr 2022 22:45:04 +0200
parents 5315a1f26c11
children a336c53b6ffb
files src/eval.c src/testdir/test_vim9_import.vim src/version.c src/vim9script.c
diffstat 4 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -6159,7 +6159,7 @@ handle_subscript(
 	    char_u	*exp_name;
 	    int		cc;
 	    int		idx;
-	    ufunc_T	*ufunc;
+	    ufunc_T	*ufunc = NULL;
 	    type_T	*type;
 
 	    // Found script from "import {name} as name", script item name must
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -1137,6 +1137,25 @@ def Test_autoload_import_relative_autolo
   delete('autoload', 'rf')
 enddef
 
+def Test_autoload_import_deleted()
+  var lines =<< trim END
+      vim9script
+      export const FOO = 1
+  END
+  writefile(lines, 'Xa.vim')
+
+  lines =<< trim END
+      vim9script
+      import autoload './Xa.vim'
+
+      delete('Xa.vim')
+      var x = Xa.FOO
+  END
+  v9.CheckScriptFailure(lines, 'E484:')
+
+  delete('Xdir', 'rf')
+enddef
+
 func Test_import_in_diffexpr()
   CheckExecutable diff
 
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4821,
+/**/
     4820,
 /**/
     4819,
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -713,7 +713,10 @@ find_exported(
     if (script->sn_import_autoload && script->sn_state == SN_STATE_NOT_LOADED)
     {
 	if (do_source(script->sn_name, FALSE, DOSO_NONE, NULL) == FAIL)
+	{
+	    semsg(_(e_cant_open_file_str), script->sn_name);
 	    return -1;
+	}
     }
 
     // Find name in "script".