0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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.
This commit is contained in:
Bram Moolenaar
2017-02-23 14:25:17 +01:00
parent 218426896c
commit f06e5a549f
2 changed files with 18 additions and 24 deletions

View File

@@ -1898,6 +1898,8 @@ get_lval(
* Loop until no more [idx] or .key is following. * Loop until no more [idx] or .key is following.
*/ */
lp->ll_tv = &v->di_tv; 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)) 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) if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
@@ -1955,7 +1957,6 @@ get_lval(
{ {
if (!quiet) if (!quiet)
EMSG(_(e_dictrange)); EMSG(_(e_dictrange));
if (!empty1)
clear_tv(&var1); clear_tv(&var1);
return NULL; return NULL;
} }
@@ -1964,7 +1965,6 @@ get_lval(
{ {
if (!quiet) if (!quiet)
EMSG(_("E709: [:] requires a List value")); EMSG(_("E709: [:] requires a List value"));
if (!empty1)
clear_tv(&var1); clear_tv(&var1);
return NULL; return NULL;
} }
@@ -1976,14 +1976,12 @@ get_lval(
lp->ll_empty2 = FALSE; lp->ll_empty2 = FALSE;
if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */ if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */
{ {
if (!empty1)
clear_tv(&var1); clear_tv(&var1);
return NULL; return NULL;
} }
if (get_tv_string_chk(&var2) == NULL) if (get_tv_string_chk(&var2) == NULL)
{ {
/* not a number or string */ /* not a number or string */
if (!empty1)
clear_tv(&var1); clear_tv(&var1);
clear_tv(&var2); clear_tv(&var2);
return NULL; return NULL;
@@ -1998,9 +1996,7 @@ get_lval(
{ {
if (!quiet) if (!quiet)
EMSG(_(e_missbrac)); EMSG(_(e_missbrac));
if (!empty1)
clear_tv(&var1); clear_tv(&var1);
if (lp->ll_range && !lp->ll_empty2)
clear_tv(&var2); clear_tv(&var2);
return NULL; return NULL;
} }
@@ -2064,7 +2060,6 @@ get_lval(
{ {
if (!quiet) if (!quiet)
EMSG2(_(e_dictkey), key); EMSG2(_(e_dictkey), key);
if (len == -1)
clear_tv(&var1); clear_tv(&var1);
return NULL; return NULL;
} }
@@ -2072,7 +2067,6 @@ get_lval(
lp->ll_newkey = vim_strsave(key); lp->ll_newkey = vim_strsave(key);
else else
lp->ll_newkey = vim_strnsave(key, len); lp->ll_newkey = vim_strnsave(key, len);
if (len == -1)
clear_tv(&var1); clear_tv(&var1);
if (lp->ll_newkey == NULL) if (lp->ll_newkey == NULL)
p = NULL; p = NULL;
@@ -2086,7 +2080,6 @@ get_lval(
return NULL; return NULL;
} }
if (len == -1)
clear_tv(&var1); clear_tv(&var1);
lp->ll_tv = &lp->ll_di->di_tv; lp->ll_tv = &lp->ll_di->di_tv;
} }
@@ -2098,11 +2091,10 @@ get_lval(
if (empty1) if (empty1)
lp->ll_n1 = 0; lp->ll_n1 = 0;
else else
{
lp->ll_n1 = (long)get_tv_number(&var1);
/* is number or string */ /* is number or string */
lp->ll_n1 = (long)get_tv_number(&var1);
clear_tv(&var1); clear_tv(&var1);
}
lp->ll_dict = NULL; lp->ll_dict = NULL;
lp->ll_list = lp->ll_tv->vval.v_list; lp->ll_list = lp->ll_tv->vval.v_list;
lp->ll_li = list_find(lp->ll_list, lp->ll_n1); lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
@@ -2116,7 +2108,6 @@ get_lval(
} }
if (lp->ll_li == NULL) if (lp->ll_li == NULL)
{ {
if (lp->ll_range && !lp->ll_empty2)
clear_tv(&var2); clear_tv(&var2);
if (!quiet) if (!quiet)
EMSGN(_(e_listidx), lp->ll_n1); EMSGN(_(e_listidx), lp->ll_n1);
@@ -2161,6 +2152,7 @@ get_lval(
} }
} }
clear_tv(&var1);
return p; return p;
} }

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
352,
/**/ /**/
351, 351,
/**/ /**/