Mercurial > vim
changeset 10926:7dab3a9cb933 v8.0.0352
patch 8.0.0352: not easy to see when a typval needs to be cleared
commit https://github.com/vim/vim/commit/f06e5a549f42396be3478ccc1b5f03be64e1173e
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 23 14:25:17 2017 +0100
patch 8.0.0352: not easy to see when a typval needs to be cleared
Problem: The condition for when a typval needs to be cleared is too
complicated.
Solution: Init the type to VAR_UNKNOWN and clear it always.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 23 Feb 2017 14:30:05 +0100 |
parents | 965446be9760 |
children | fdb7dc68bf6b |
files | src/eval.c src/version.c |
diffstat | 2 files changed, 18 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -1898,6 +1898,8 @@ get_lval( * Loop until no more [idx] or .key is following. */ lp->ll_tv = &v->di_tv; + var1.v_type = VAR_UNKNOWN; + var2.v_type = VAR_UNKNOWN; while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) { if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) @@ -1955,8 +1957,7 @@ get_lval( { if (!quiet) EMSG(_(e_dictrange)); - if (!empty1) - clear_tv(&var1); + clear_tv(&var1); return NULL; } if (rettv != NULL && (rettv->v_type != VAR_LIST @@ -1964,8 +1965,7 @@ get_lval( { if (!quiet) EMSG(_("E709: [:] requires a List value")); - if (!empty1) - clear_tv(&var1); + clear_tv(&var1); return NULL; } p = skipwhite(p + 1); @@ -1976,15 +1976,13 @@ get_lval( lp->ll_empty2 = FALSE; if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */ { - if (!empty1) - clear_tv(&var1); + clear_tv(&var1); return NULL; } if (get_tv_string_chk(&var2) == NULL) { /* not a number or string */ - if (!empty1) - clear_tv(&var1); + clear_tv(&var1); clear_tv(&var2); return NULL; } @@ -1998,10 +1996,8 @@ get_lval( { if (!quiet) EMSG(_(e_missbrac)); - if (!empty1) - clear_tv(&var1); - if (lp->ll_range && !lp->ll_empty2) - clear_tv(&var2); + clear_tv(&var1); + clear_tv(&var2); return NULL; } @@ -2064,16 +2060,14 @@ get_lval( { if (!quiet) EMSG2(_(e_dictkey), key); - if (len == -1) - clear_tv(&var1); + clear_tv(&var1); return NULL; } if (len == -1) lp->ll_newkey = vim_strsave(key); else lp->ll_newkey = vim_strnsave(key, len); - if (len == -1) - clear_tv(&var1); + clear_tv(&var1); if (lp->ll_newkey == NULL) p = NULL; break; @@ -2086,8 +2080,7 @@ get_lval( return NULL; } - if (len == -1) - clear_tv(&var1); + clear_tv(&var1); lp->ll_tv = &lp->ll_di->di_tv; } else @@ -2098,11 +2091,10 @@ get_lval( if (empty1) lp->ll_n1 = 0; else - { + /* is number or string */ lp->ll_n1 = (long)get_tv_number(&var1); - /* is number or string */ - clear_tv(&var1); - } + clear_tv(&var1); + lp->ll_dict = NULL; lp->ll_list = lp->ll_tv->vval.v_list; lp->ll_li = list_find(lp->ll_list, lp->ll_n1); @@ -2116,8 +2108,7 @@ get_lval( } if (lp->ll_li == NULL) { - if (lp->ll_range && !lp->ll_empty2) - clear_tv(&var2); + clear_tv(&var2); if (!quiet) EMSGN(_(e_listidx), lp->ll_n1); return NULL; @@ -2161,6 +2152,7 @@ get_lval( } } + clear_tv(&var1); return p; }