Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
22309:59a0d8be7c65 | 22310:74d0a7a30583 |
---|---|
759 int ret = FAIL; | 759 int ret = FAIL; |
760 int defcount = ufunc->uf_args.ga_len - argc; | 760 int defcount = ufunc->uf_args.ga_len - argc; |
761 sctx_T save_current_sctx = current_sctx; | 761 sctx_T save_current_sctx = current_sctx; |
762 int breakcheck_count = 0; | 762 int breakcheck_count = 0; |
763 int called_emsg_before = called_emsg; | 763 int called_emsg_before = called_emsg; |
764 int save_suppress_errthrow = suppress_errthrow; | |
764 | 765 |
765 // Get pointer to item in the stack. | 766 // Get pointer to item in the stack. |
766 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) | 767 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx) |
767 | 768 |
768 // Get pointer to item at the bottom of the stack, -1 is the bottom. | 769 // Get pointer to item at the bottom of the stack, -1 is the bottom. |
904 // Following errors are in the function, not the caller. | 905 // Following errors are in the function, not the caller. |
905 // Commands behave like vim9script. | 906 // Commands behave like vim9script. |
906 estack_push_ufunc(ufunc, 1); | 907 estack_push_ufunc(ufunc, 1); |
907 current_sctx = ufunc->uf_script_ctx; | 908 current_sctx = ufunc->uf_script_ctx; |
908 current_sctx.sc_version = SCRIPT_VERSION_VIM9; | 909 current_sctx.sc_version = SCRIPT_VERSION_VIM9; |
910 | |
911 // Do turn errors into exceptions. | |
912 suppress_errthrow = FALSE; | |
909 | 913 |
910 // Decide where to start execution, handles optional arguments. | 914 // Decide where to start execution, handles optional arguments. |
911 init_instr_idx(ufunc, argc, &ectx); | 915 init_instr_idx(ufunc, argc, &ectx); |
912 | 916 |
913 for (;;) | 917 for (;;) |
1882 STACK_TV_VAR(iptr->isn_arg.forloop.for_idx); | 1886 STACK_TV_VAR(iptr->isn_arg.forloop.for_idx); |
1883 | 1887 |
1884 // push the next item from the list | 1888 // push the next item from the list |
1885 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) | 1889 if (GA_GROW(&ectx.ec_stack, 1) == FAIL) |
1886 goto failed; | 1890 goto failed; |
1887 if (++idxtv->vval.v_number >= list->lv_len) | 1891 ++idxtv->vval.v_number; |
1892 if (list == NULL || idxtv->vval.v_number >= list->lv_len) | |
1888 // past the end of the list, jump to "endfor" | 1893 // past the end of the list, jump to "endfor" |
1889 ectx.ec_iidx = iptr->isn_arg.forloop.for_end; | 1894 ectx.ec_iidx = iptr->isn_arg.forloop.for_end; |
1890 else if (list->lv_first == &range_list_item) | 1895 else if (list->lv_first == &range_list_item) |
1891 { | 1896 { |
1892 // non-materialized range() list | 1897 // non-materialized range() list |
2710 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx) | 2715 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx) |
2711 clear_tv(STACK_TV(idx)); | 2716 clear_tv(STACK_TV(idx)); |
2712 | 2717 |
2713 vim_free(ectx.ec_stack.ga_data); | 2718 vim_free(ectx.ec_stack.ga_data); |
2714 vim_free(ectx.ec_trystack.ga_data); | 2719 vim_free(ectx.ec_trystack.ga_data); |
2720 | |
2721 // Not sure if this is necessary. | |
2722 suppress_errthrow = save_suppress_errthrow; | |
2715 | 2723 |
2716 if (ret != OK && called_emsg == called_emsg_before) | 2724 if (ret != OK && called_emsg == called_emsg_before) |
2717 semsg(_(e_unknown_error_while_executing_str), | 2725 semsg(_(e_unknown_error_while_executing_str), |
2718 printable_func_name(ufunc)); | 2726 printable_func_name(ufunc)); |
2719 return ret; | 2727 return ret; |