comparison 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
comparison
equal deleted inserted replaced
25357:2cf7cefa5bfa 25358:f03271631eb5
970 // exists, from sn_vars and move the value into sn_all_vars 970 // exists, from sn_vars and move the value into sn_all_vars
971 // if "func_defined" is non-zero. 971 // if "func_defined" is non-zero.
972 hide_script_var(si, i, func_defined); 972 hide_script_var(si, i, func_defined);
973 } 973 }
974 974
975 // TODO: is this needed?
976 cstack->cs_script_var_len[cstack->cs_idx] = si->sn_var_vals.ga_len;
977
978 if (cstack->cs_idx == 0) 975 if (cstack->cs_idx == 0)
979 si->sn_current_block_id = 0; 976 si->sn_current_block_id = 0;
980 else 977 else
981 si->sn_current_block_id = cstack->cs_block_id[cstack->cs_idx - 1]; 978 si->sn_current_block_id = cstack->cs_block_id[cstack->cs_idx - 1];
982 } 979 }
1176 { 1173 {
1177 if (in_vim9script() && SCRIPT_ID_VALID(current_sctx.sc_sid)) 1174 if (in_vim9script() && SCRIPT_ID_VALID(current_sctx.sc_sid))
1178 { 1175 {
1179 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); 1176 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
1180 int i; 1177 int i;
1178 int func_defined = cstack->cs_flags[cstack->cs_idx]
1179 & CSF_FUNC_DEF;
1181 1180
1182 // Any variables defined in the previous round are no longer 1181 // Any variables defined in the previous round are no longer
1183 // visible. 1182 // visible.
1184 for (i = cstack->cs_script_var_len[cstack->cs_idx]; 1183 for (i = cstack->cs_script_var_len[cstack->cs_idx];
1185 i < si->sn_var_vals.ga_len; ++i) 1184 i < si->sn_var_vals.ga_len; ++i)
1190 // happens when it was defined in an inner block and no 1189 // happens when it was defined in an inner block and no
1191 // functions were defined there. 1190 // functions were defined there.
1192 if (sv->sv_name != NULL) 1191 if (sv->sv_name != NULL)
1193 // Remove a variable declared inside the block, if it 1192 // Remove a variable declared inside the block, if it
1194 // still exists, from sn_vars. 1193 // still exists, from sn_vars.
1195 hide_script_var(si, i, FALSE); 1194 hide_script_var(si, i, func_defined);
1196 } 1195 }
1197 cstack->cs_script_var_len[cstack->cs_idx] =
1198 si->sn_var_vals.ga_len;
1199 } 1196 }
1200 } 1197 }
1201 cstack->cs_flags[cstack->cs_idx] = 1198 cstack->cs_flags[cstack->cs_idx] =
1202 eap->cmdidx == CMD_while ? CSF_WHILE : CSF_FOR; 1199 eap->cmdidx == CMD_while ? CSF_WHILE : CSF_FOR;
1203 1200
1220 evalarg_T evalarg; 1217 evalarg_T evalarg;
1221 1218
1222 /* 1219 /*
1223 * ":for var in list-expr" 1220 * ":for var in list-expr"
1224 */ 1221 */
1225 CLEAR_FIELD(evalarg); 1222 fill_evalarg_from_eap(&evalarg, eap, skip);
1226 evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE;
1227 if (getline_equal(eap->getline, eap->cookie, getsourceline))
1228 {
1229 evalarg.eval_getline = eap->getline;
1230 evalarg.eval_cookie = eap->cookie;
1231 }
1232
1233 if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0) 1223 if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0)
1234 { 1224 {
1235 // Jumping here from a ":continue" or ":endfor": use the 1225 // Jumping here from a ":continue" or ":endfor": use the
1236 // previously evaluated list. 1226 // previously evaluated list.
1237 fi = cstack->cs_forinfo[cstack->cs_idx]; 1227 fi = cstack->cs_forinfo[cstack->cs_idx];