Mercurial > vim
diff src/vim9execute.c @ 22310:74d0a7a30583 v8.2.1704
patch 8.2.1704: Vim9: crash in for loop when autoload script has an error
Commit: https://github.com/vim/vim/commit/77e5dcc36a82da040072d74e3ced410d15c42757
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 17 21:29:03 2020 +0200
patch 8.2.1704: Vim9: crash in for loop when autoload script has an error
Problem: Vim9: crash in for loop when autoload script has an error.
Solution: Reset suppress_errthrow. Check for NULL list. (closes https://github.com/vim/vim/issues/6967)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 17 Sep 2020 21:30:03 +0200 |
parents | 36e8e046c335 |
children | 41e118669df3 |
line wrap: on
line diff
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -761,6 +761,7 @@ call_def_function( sctx_T save_current_sctx = current_sctx; int breakcheck_count = 0; int called_emsg_before = called_emsg; + int save_suppress_errthrow = suppress_errthrow; // Get pointer to item in the stack. #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) @@ -907,6 +908,9 @@ call_def_function( current_sctx = ufunc->uf_script_ctx; current_sctx.sc_version = SCRIPT_VERSION_VIM9; + // Do turn errors into exceptions. + suppress_errthrow = FALSE; + // Decide where to start execution, handles optional arguments. init_instr_idx(ufunc, argc, &ectx); @@ -1884,7 +1888,8 @@ call_def_function( // push the next item from the list if (GA_GROW(&ectx.ec_stack, 1) == FAIL) goto failed; - if (++idxtv->vval.v_number >= list->lv_len) + ++idxtv->vval.v_number; + if (list == NULL || idxtv->vval.v_number >= list->lv_len) // past the end of the list, jump to "endfor" ectx.ec_iidx = iptr->isn_arg.forloop.for_end; else if (list->lv_first == &range_list_item) @@ -2713,6 +2718,9 @@ failed_early: vim_free(ectx.ec_stack.ga_data); vim_free(ectx.ec_trystack.ga_data); + // Not sure if this is necessary. + suppress_errthrow = save_suppress_errthrow; + if (ret != OK && called_emsg == called_emsg_before) semsg(_(e_unknown_error_while_executing_str), printable_func_name(ufunc));