]> granicus.if.org Git - vim/commitdiff
patch 8.0.0352: not easy to see when a typval needs to be cleared v8.0.0352
authorBram Moolenaar <Bram@vim.org>
Thu, 23 Feb 2017 13:25:17 +0000 (14:25 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 23 Feb 2017 13:25:17 +0000 (14:25 +0100)
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.

src/eval.c
src/version.c

index c4154d01d4f4fe8f74fdbc3b5aba666b4678d316..725e540b95cc148812312871429a2565cd36c5e8 100644 (file)
@@ -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;
 }
 
index b51f04d40b25a3d55013b1bf026fb70704e43070..021704a853a8919fce6c8fd77c0542390718fa46 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    352,
 /**/
     351,
 /**/