]> granicus.if.org Git - vim/commitdiff
patch 8.2.1739: Vim9: crash when compiling a manually defined function v8.2.1739
authorBram Moolenaar <Bram@vim.org>
Fri, 25 Sep 2020 19:47:28 +0000 (21:47 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 25 Sep 2020 19:47:28 +0000 (21:47 +0200)
Problem:    Vim9: crash when compiling a manually defined function. (Antony
            Scriven)
Solution:   Check that the script ID is positive. (closes #7012)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 57d36d9db2e6b0433a7bb98be8031226a743b34e..4a4047fb34f9d87af3f8eb2ec70cdbe7ce168fa9 100644 (file)
@@ -2755,7 +2755,7 @@ def Test_vim9_autoload_error()
     exe 'set rtp^=' .. getcwd() .. '/Xruntime'
     call crash#func()
     call writefile(['ok'], 'Xdidit')
-    qall
+    qall!
   END
   writefile(lines, 'Xscript')
   RunVim([], [], '-S Xscript')
@@ -2817,7 +2817,7 @@ enddef
 def Test_invalid_sid()
   assert_fails('func <SNR>1234_func', 'E123:')
 
-  if RunVim([], ['wq Xdidit'], '+"func <SNR>1_func"')
+  if RunVim([], ['wq! Xdidit'], '+"func <SNR>1_func"')
     assert_equal([], readfile('Xdidit'))
   endif
   delete('Xdidit')
@@ -2831,6 +2831,27 @@ def Test_unset_any_variable()
   CheckDefAndScriptSuccess(lines)
 enddef
 
+def Test_define_func_at_command_line()
+  # run in a separate Vim instance to avoid the script context
+  let lines =<< trim END
+    func CheckAndQuit()
+      call assert_fails('call Afunc()', 'E117: Unknown function: Bfunc')
+      call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd')
+    endfunc
+  END
+  writefile([''], 'Xdidcmd')
+  writefile(lines, 'XcallFunc')
+  let buf = RunVimInTerminal('-S XcallFunc', #{rows: 6})
+  # define Afunc() on the command line
+  term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
+  term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
+  WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))})
+
+  call StopVimInTerminal(buf)
+  delete('XcallFunc')
+  delete('Xdidcmd')
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
index 0b3c5f559d598e7736f761137658c86be68f88a3..374f5a114e609fc538af2bc2b2fd76dd9fd09aa8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1739,
 /**/
     1738,
 /**/
index 6ed166d47927fc9b35d3a3961494baae35255a41..5d0ccb65957d438e0d13af855b83a78d7b578e49 100644 (file)
@@ -277,9 +277,12 @@ script_is_vim9()
 lookup_script(char_u *name, size_t len, int vim9script)
 {
     int                    cc;
-    hashtab_T      *ht = &SCRIPT_VARS(current_sctx.sc_sid);
+    hashtab_T      *ht;
     dictitem_T     *di;
 
+    if (current_sctx.sc_sid <= 0)
+       return FAIL;
+    ht = &SCRIPT_VARS(current_sctx.sc_sid);
     if (vim9script && !script_is_vim9())
        return FAIL;
     cc = name[len];