diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-10-09 22:04:29 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-10-09 22:04:29 +0200 |
commit | e8211a33dcb0ac6e29aad6699160fdc2e5fa2024 (patch) | |
tree | 2bc5264f9957a5aaca86762be2b74d1c8efaeead /src/vim9compile.c | |
parent | 11416321ff45e2bf3d456f332dc9d1836a8d171a (diff) | |
download | vim-git-e8211a33dcb0ac6e29aad6699160fdc2e5fa2024.tar.gz |
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spotv8.2.1817
Problem: Vim9: wrong instruction when reusing a local variable spot.
Solution: Clear a newly allocated local variable. (closes #7080)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r-- | src/vim9compile.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c index a6bdcc3f3..74be262a5 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1690,7 +1690,12 @@ generate_EXECCONCAT(cctx_T *cctx, int count) * Return the variable or NULL if it failed. */ static lvar_T * -reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type) +reserve_local( + cctx_T *cctx, + char_u *name, + size_t len, + int isConst, + type_T *type) { lvar_T *lvar; @@ -1703,6 +1708,7 @@ reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type) if (ga_grow(&cctx->ctx_locals, 1) == FAIL) return NULL; lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; + CLEAR_POINTER(lvar); // Every local variable uses the next entry on the stack. We could re-use // the last ones when leaving a scope, but then variables used in a closure @@ -4438,7 +4444,6 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx) char_u *name_start = eap->arg; char_u *name_end = to_name_end(eap->arg, TRUE); char_u *lambda_name; - lvar_T *lvar; ufunc_T *ufunc; int r; @@ -4487,8 +4492,9 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx) else { // Define a local variable for the function reference. - lvar = reserve_local(cctx, name_start, name_end - name_start, + lvar_T *lvar = reserve_local(cctx, name_start, name_end - name_start, TRUE, ufunc->uf_func_type); + if (lvar == NULL) return NULL; if (generate_FUNCREF(cctx, ufunc) == FAIL) |