Mercurial > vim
diff src/ex_eval.c @ 25358:f03271631eb5 v8.2.3216
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Commit: https://github.com/vim/vim/commit/2eb6fc3b52148f961e804ec2be361d531ff770d8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 25 14:13:53 2021 +0200
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Problem: Vim9: crash when using variable in a loop at script level.
Solution: Do not clear the variable if a function was defined.
Do not create a new entry in sn_var_vals every time.
(closes #8628)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 25 Jul 2021 14:15:04 +0200 |
parents | 078edc1821bf |
children | 2063b858cad9 |
line wrap: on
line diff
--- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -972,9 +972,6 @@ leave_block(cstack_T *cstack) hide_script_var(si, i, func_defined); } - // TODO: is this needed? - cstack->cs_script_var_len[cstack->cs_idx] = si->sn_var_vals.ga_len; - if (cstack->cs_idx == 0) si->sn_current_block_id = 0; else @@ -1178,6 +1175,8 @@ ex_while(exarg_T *eap) { scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); int i; + int func_defined = cstack->cs_flags[cstack->cs_idx] + & CSF_FUNC_DEF; // Any variables defined in the previous round are no longer // visible. @@ -1192,10 +1191,8 @@ ex_while(exarg_T *eap) if (sv->sv_name != NULL) // Remove a variable declared inside the block, if it // still exists, from sn_vars. - hide_script_var(si, i, FALSE); + hide_script_var(si, i, func_defined); } - cstack->cs_script_var_len[cstack->cs_idx] = - si->sn_var_vals.ga_len; } } cstack->cs_flags[cstack->cs_idx] = @@ -1222,14 +1219,7 @@ ex_while(exarg_T *eap) /* * ":for var in list-expr" */ - CLEAR_FIELD(evalarg); - evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE; - if (getline_equal(eap->getline, eap->cookie, getsourceline)) - { - evalarg.eval_getline = eap->getline; - evalarg.eval_cookie = eap->cookie; - } - + fill_evalarg_from_eap(&evalarg, eap, skip); if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0) { // Jumping here from a ":continue" or ":endfor": use the