Mercurial > vim
comparison src/vim9compile.c @ 22537:9870e8b6ed78 v8.2.1817
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Commit: https://github.com/vim/vim/commit/e8211a33dcb0ac6e29aad6699160fdc2e5fa2024
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Oct 9 22:04:29 2020 +0200
patch 8.2.1817: Vim9: wrong instruction when reusing a local variable spot
Problem: Vim9: wrong instruction when reusing a local variable spot.
Solution: Clear a newly allocated local variable. (closes https://github.com/vim/vim/issues/7080)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 09 Oct 2020 22:15:03 +0200 |
parents | ac8c4a8b8cba |
children | c271498e03b2 |
comparison
equal
deleted
inserted
replaced
22536:827f19fed49b | 22537:9870e8b6ed78 |
---|---|
1688 /* | 1688 /* |
1689 * Reserve space for a local variable. | 1689 * Reserve space for a local variable. |
1690 * Return the variable or NULL if it failed. | 1690 * Return the variable or NULL if it failed. |
1691 */ | 1691 */ |
1692 static lvar_T * | 1692 static lvar_T * |
1693 reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type) | 1693 reserve_local( |
1694 cctx_T *cctx, | |
1695 char_u *name, | |
1696 size_t len, | |
1697 int isConst, | |
1698 type_T *type) | |
1694 { | 1699 { |
1695 lvar_T *lvar; | 1700 lvar_T *lvar; |
1696 | 1701 |
1697 if (lookup_arg(name, len, NULL, NULL, NULL, cctx) == OK) | 1702 if (lookup_arg(name, len, NULL, NULL, NULL, cctx) == OK) |
1698 { | 1703 { |
1701 } | 1706 } |
1702 | 1707 |
1703 if (ga_grow(&cctx->ctx_locals, 1) == FAIL) | 1708 if (ga_grow(&cctx->ctx_locals, 1) == FAIL) |
1704 return NULL; | 1709 return NULL; |
1705 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; | 1710 lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++; |
1711 CLEAR_POINTER(lvar); | |
1706 | 1712 |
1707 // Every local variable uses the next entry on the stack. We could re-use | 1713 // Every local variable uses the next entry on the stack. We could re-use |
1708 // the last ones when leaving a scope, but then variables used in a closure | 1714 // the last ones when leaving a scope, but then variables used in a closure |
1709 // might get overwritten. To keep things simple do not re-use stack | 1715 // might get overwritten. To keep things simple do not re-use stack |
1710 // entries. This is less efficient, but memory is cheap these days. | 1716 // entries. This is less efficient, but memory is cheap these days. |
4436 { | 4442 { |
4437 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; | 4443 int is_global = *eap->arg == 'g' && eap->arg[1] == ':'; |
4438 char_u *name_start = eap->arg; | 4444 char_u *name_start = eap->arg; |
4439 char_u *name_end = to_name_end(eap->arg, TRUE); | 4445 char_u *name_end = to_name_end(eap->arg, TRUE); |
4440 char_u *lambda_name; | 4446 char_u *lambda_name; |
4441 lvar_T *lvar; | |
4442 ufunc_T *ufunc; | 4447 ufunc_T *ufunc; |
4443 int r; | 4448 int r; |
4444 | 4449 |
4445 if (eap->forceit) | 4450 if (eap->forceit) |
4446 { | 4451 { |
4485 r = generate_NEWFUNC(cctx, lambda_name, func_name); | 4490 r = generate_NEWFUNC(cctx, lambda_name, func_name); |
4486 } | 4491 } |
4487 else | 4492 else |
4488 { | 4493 { |
4489 // Define a local variable for the function reference. | 4494 // Define a local variable for the function reference. |
4490 lvar = reserve_local(cctx, name_start, name_end - name_start, | 4495 lvar_T *lvar = reserve_local(cctx, name_start, name_end - name_start, |
4491 TRUE, ufunc->uf_func_type); | 4496 TRUE, ufunc->uf_func_type); |
4497 | |
4492 if (lvar == NULL) | 4498 if (lvar == NULL) |
4493 return NULL; | 4499 return NULL; |
4494 if (generate_FUNCREF(cctx, ufunc) == FAIL) | 4500 if (generate_FUNCREF(cctx, ufunc) == FAIL) |
4495 return NULL; | 4501 return NULL; |
4496 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); | 4502 r = generate_STORE(cctx, ISN_STORE, lvar->lv_idx, NULL); |