Mercurial > vim
diff src/vim9compile.c @ 21463:7f36d36f7195 v8.2.1282
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
Commit: https://github.com/vim/vim/commit/6c4bfe4b31e8c5d3c4809536ab6e4835d50f0f67
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 23 18:26:30 2020 +0200
patch 8.2.1282: Vim9: crash when using CheckScriptFailure()
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 23 Jul 2020 18:30:04 +0200 |
parents | 8cc1555f2445 |
children | b5d4ab124782 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -6945,6 +6945,7 @@ compile_def_function(ufunc_T *ufunc, int 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 + 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)