• R/O
  • SSH

vim: 提交

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

修订版6fe9536694ff6814aa378132e3d30a0cb610243e (tree)
时间2020-09-26 05:00:04
作者Bram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.1739: Vim9: crash when compiling a manually defined function

Commit: https://github.com/vim/vim/commit/9c4f55204fdf8909f4e3515a32a542044bf9f943
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Sep 25 21:47:28 2020 +0200

patch 8.2.1739: Vim9: crash when compiling a manually defined function
Problem: Vim9: crash when compiling a manually defined function. (Antony
Scriven)
Solution: Check that the script ID is positive. (closes #7012)

更改概述

差异

diff -r 4b2dec9c0c29 -r 6fe9536694ff src/testdir/test_vim9_script.vim
--- a/src/testdir/test_vim9_script.vim Thu Sep 24 23:15:05 2020 +0200
+++ b/src/testdir/test_vim9_script.vim Fri Sep 25 22:00:04 2020 +0200
@@ -2755,7 +2755,7 @@
27552755 exe 'set rtp^=' .. getcwd() .. '/Xruntime'
27562756 call crash#func()
27572757 call writefile(['ok'], 'Xdidit')
2758- qall
2758+ qall!
27592759 END
27602760 writefile(lines, 'Xscript')
27612761 RunVim([], [], '-S Xscript')
@@ -2817,7 +2817,7 @@
28172817 def Test_invalid_sid()
28182818 assert_fails('func <SNR>1234_func', 'E123:')
28192819
2820- if RunVim([], ['wq Xdidit'], '+"func <SNR>1_func"')
2820+ if RunVim([], ['wq! Xdidit'], '+"func <SNR>1_func"')
28212821 assert_equal([], readfile('Xdidit'))
28222822 endif
28232823 delete('Xdidit')
@@ -2831,6 +2831,27 @@
28312831 CheckDefAndScriptSuccess(lines)
28322832 enddef
28332833
2834+def Test_define_func_at_command_line()
2835+ # run in a separate Vim instance to avoid the script context
2836+ let lines =<< trim END
2837+ func CheckAndQuit()
2838+ call assert_fails('call Afunc()', 'E117: Unknown function: Bfunc')
2839+ call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd')
2840+ endfunc
2841+ END
2842+ writefile([''], 'Xdidcmd')
2843+ writefile(lines, 'XcallFunc')
2844+ let buf = RunVimInTerminal('-S XcallFunc', #{rows: 6})
2845+ # define Afunc() on the command line
2846+ term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
2847+ term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
2848+ WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))})
2849+
2850+ call StopVimInTerminal(buf)
2851+ delete('XcallFunc')
2852+ delete('Xdidcmd')
2853+enddef
2854+
28342855 " Keep this last, it messes up highlighting.
28352856 def Test_substitute_cmd()
28362857 new
diff -r 4b2dec9c0c29 -r 6fe9536694ff src/version.c
--- a/src/version.c Thu Sep 24 23:15:05 2020 +0200
+++ b/src/version.c Fri Sep 25 22:00:04 2020 +0200
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 1739,
755+/**/
754756 1738,
755757 /**/
756758 1737,
diff -r 4b2dec9c0c29 -r 6fe9536694ff src/vim9compile.c
--- a/src/vim9compile.c Thu Sep 24 23:15:05 2020 +0200
+++ b/src/vim9compile.c Fri Sep 25 22:00:04 2020 +0200
@@ -277,9 +277,12 @@
277277 lookup_script(char_u *name, size_t len, int vim9script)
278278 {
279279 int cc;
280- hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
280+ hashtab_T *ht;
281281 dictitem_T *di;
282282
283+ if (current_sctx.sc_sid <= 0)
284+ return FAIL;
285+ ht = &SCRIPT_VARS(current_sctx.sc_sid);
283286 if (vim9script && !script_is_vim9())
284287 return FAIL;
285288 cc = name[len];
Show on old repository browser