diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-07-23 18:26:30 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-07-23 18:26:30 +0200 |
commit | 6c4bfe4b31e8c5d3c4809536ab6e4835d50f0f67 (patch) | |
tree | 11ed390d58bf488b11d865292e0d6f03f72e718a | |
parent | 2d06bfde29bd3a62fc85823d2aa719ef943bd319 (diff) | |
download | vim-git-8.2.1282.tar.gz |
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()v8.2.1282
Problem: Vim9: crash when using CheckScriptFailure() in
Test_vim9script_call_fail_decl().
Solution: Do not decrement the def_functions len unless the function was
newly added.
-rw-r--r-- | src/testdir/test_vim9_func.vim | 6 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 17 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index ed5972185..25c40c8b9 100644 --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -258,7 +258,7 @@ endfunc def Test_call_funcref() assert_equal(3, g:SomeFunc('abc')) - assert_fails('NotAFunc()', 'E117:') + assert_fails('NotAFunc()', 'E117:') # comment after call assert_fails('g:NotAFunc()', 'E117:') let lines =<< trim END @@ -425,9 +425,7 @@ def Test_vim9script_call_fail_decl() enddef defcompile END - writefile(lines, 'Xcall_decl.vim') - assert_fails('source Xcall_decl.vim', 'E1054:') - delete('Xcall_decl.vim') + CheckScriptFailure(lines, 'E1054:') enddef def Test_vim9script_call_fail_type() diff --git a/src/version.c b/src/version.c index 4286eb0b3..4ef305162 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1282, +/**/ 1281, /**/ 1280, diff --git a/src/vim9compile.c b/src/vim9compile.c index 394433a12..0fe0b16dd 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -6945,6 +6945,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx) sctx_T save_current_sctx = current_sctx; int do_estack_push; int emsg_before = called_emsg; + int new_def_function = FALSE; // When using a function that was compiled before: Free old instructions. // Otherwise add a new entry in "def_functions". @@ -6954,8 +6955,12 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx) + ufunc->uf_dfunc_idx; delete_def_function_contents(dfunc); } - else if (add_def_function(ufunc) == FAIL) - return FAIL; + else + { + if (add_def_function(ufunc) == FAIL) + return FAIL; + new_def_function = TRUE; + } ufunc->uf_def_status = UF_COMPILING; @@ -7439,10 +7444,14 @@ erret: delete_instr(((isn_T *)instr->ga_data) + idx); ga_clear(instr); - // if using the last entry in the table we might as well remove it - if (!dfunc->df_deleted + // If using the last entry in the table and it was added above, we + // might as well remove it. + if (!dfunc->df_deleted && new_def_function && ufunc->uf_dfunc_idx == def_functions.ga_len - 1) + { --def_functions.ga_len; + ufunc->uf_dfunc_idx = 0; + } ufunc->uf_def_status = UF_NOT_COMPILED; while (cctx.ctx_scope != NULL) |