comparison src/eval.c @ 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 fd1760f8c215
children e05695e59f6d
comparison
equal deleted inserted replaced
10925:965446be9760 10926:7dab3a9cb933
1896 1896
1897 /* 1897 /*
1898 * Loop until no more [idx] or .key is following. 1898 * Loop until no more [idx] or .key is following.
1899 */ 1899 */
1900 lp->ll_tv = &v->di_tv; 1900 lp->ll_tv = &v->di_tv;
1901 var1.v_type = VAR_UNKNOWN;
1902 var2.v_type = VAR_UNKNOWN;
1901 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT)) 1903 while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
1902 { 1904 {
1903 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL) 1905 if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
1904 && !(lp->ll_tv->v_type == VAR_DICT 1906 && !(lp->ll_tv->v_type == VAR_DICT
1905 && lp->ll_tv->vval.v_dict != NULL)) 1907 && lp->ll_tv->vval.v_dict != NULL))
1953 { 1955 {
1954 if (lp->ll_tv->v_type == VAR_DICT) 1956 if (lp->ll_tv->v_type == VAR_DICT)
1955 { 1957 {
1956 if (!quiet) 1958 if (!quiet)
1957 EMSG(_(e_dictrange)); 1959 EMSG(_(e_dictrange));
1958 if (!empty1) 1960 clear_tv(&var1);
1959 clear_tv(&var1);
1960 return NULL; 1961 return NULL;
1961 } 1962 }
1962 if (rettv != NULL && (rettv->v_type != VAR_LIST 1963 if (rettv != NULL && (rettv->v_type != VAR_LIST
1963 || rettv->vval.v_list == NULL)) 1964 || rettv->vval.v_list == NULL))
1964 { 1965 {
1965 if (!quiet) 1966 if (!quiet)
1966 EMSG(_("E709: [:] requires a List value")); 1967 EMSG(_("E709: [:] requires a List value"));
1967 if (!empty1) 1968 clear_tv(&var1);
1968 clear_tv(&var1);
1969 return NULL; 1969 return NULL;
1970 } 1970 }
1971 p = skipwhite(p + 1); 1971 p = skipwhite(p + 1);
1972 if (*p == ']') 1972 if (*p == ']')
1973 lp->ll_empty2 = TRUE; 1973 lp->ll_empty2 = TRUE;
1974 else 1974 else
1975 { 1975 {
1976 lp->ll_empty2 = FALSE; 1976 lp->ll_empty2 = FALSE;
1977 if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */ 1977 if (eval1(&p, &var2, TRUE) == FAIL) /* recursive! */
1978 { 1978 {
1979 if (!empty1) 1979 clear_tv(&var1);
1980 clear_tv(&var1);
1981 return NULL; 1980 return NULL;
1982 } 1981 }
1983 if (get_tv_string_chk(&var2) == NULL) 1982 if (get_tv_string_chk(&var2) == NULL)
1984 { 1983 {
1985 /* not a number or string */ 1984 /* not a number or string */
1986 if (!empty1) 1985 clear_tv(&var1);
1987 clear_tv(&var1);
1988 clear_tv(&var2); 1986 clear_tv(&var2);
1989 return NULL; 1987 return NULL;
1990 } 1988 }
1991 } 1989 }
1992 lp->ll_range = TRUE; 1990 lp->ll_range = TRUE;
1996 1994
1997 if (*p != ']') 1995 if (*p != ']')
1998 { 1996 {
1999 if (!quiet) 1997 if (!quiet)
2000 EMSG(_(e_missbrac)); 1998 EMSG(_(e_missbrac));
2001 if (!empty1) 1999 clear_tv(&var1);
2002 clear_tv(&var1); 2000 clear_tv(&var2);
2003 if (lp->ll_range && !lp->ll_empty2)
2004 clear_tv(&var2);
2005 return NULL; 2001 return NULL;
2006 } 2002 }
2007 2003
2008 /* Skip to past ']'. */ 2004 /* Skip to past ']'. */
2009 ++p; 2005 ++p;
2062 /* Key does not exist in dict: may need to add it. */ 2058 /* Key does not exist in dict: may need to add it. */
2063 if (*p == '[' || *p == '.' || unlet) 2059 if (*p == '[' || *p == '.' || unlet)
2064 { 2060 {
2065 if (!quiet) 2061 if (!quiet)
2066 EMSG2(_(e_dictkey), key); 2062 EMSG2(_(e_dictkey), key);
2067 if (len == -1) 2063 clear_tv(&var1);
2068 clear_tv(&var1);
2069 return NULL; 2064 return NULL;
2070 } 2065 }
2071 if (len == -1) 2066 if (len == -1)
2072 lp->ll_newkey = vim_strsave(key); 2067 lp->ll_newkey = vim_strsave(key);
2073 else 2068 else
2074 lp->ll_newkey = vim_strnsave(key, len); 2069 lp->ll_newkey = vim_strnsave(key, len);
2075 if (len == -1) 2070 clear_tv(&var1);
2076 clear_tv(&var1);
2077 if (lp->ll_newkey == NULL) 2071 if (lp->ll_newkey == NULL)
2078 p = NULL; 2072 p = NULL;
2079 break; 2073 break;
2080 } 2074 }
2081 /* existing variable, need to check if it can be changed */ 2075 /* existing variable, need to check if it can be changed */
2084 { 2078 {
2085 clear_tv(&var1); 2079 clear_tv(&var1);
2086 return NULL; 2080 return NULL;
2087 } 2081 }
2088 2082
2089 if (len == -1) 2083 clear_tv(&var1);
2090 clear_tv(&var1);
2091 lp->ll_tv = &lp->ll_di->di_tv; 2084 lp->ll_tv = &lp->ll_di->di_tv;
2092 } 2085 }
2093 else 2086 else
2094 { 2087 {
2095 /* 2088 /*
2096 * Get the number and item for the only or first index of the List. 2089 * Get the number and item for the only or first index of the List.
2097 */ 2090 */
2098 if (empty1) 2091 if (empty1)
2099 lp->ll_n1 = 0; 2092 lp->ll_n1 = 0;
2100 else 2093 else
2101 { 2094 /* is number or string */
2102 lp->ll_n1 = (long)get_tv_number(&var1); 2095 lp->ll_n1 = (long)get_tv_number(&var1);
2103 /* is number or string */ 2096 clear_tv(&var1);
2104 clear_tv(&var1); 2097
2105 }
2106 lp->ll_dict = NULL; 2098 lp->ll_dict = NULL;
2107 lp->ll_list = lp->ll_tv->vval.v_list; 2099 lp->ll_list = lp->ll_tv->vval.v_list;
2108 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); 2100 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
2109 if (lp->ll_li == NULL) 2101 if (lp->ll_li == NULL)
2110 { 2102 {
2114 lp->ll_li = list_find(lp->ll_list, lp->ll_n1); 2106 lp->ll_li = list_find(lp->ll_list, lp->ll_n1);
2115 } 2107 }
2116 } 2108 }
2117 if (lp->ll_li == NULL) 2109 if (lp->ll_li == NULL)
2118 { 2110 {
2119 if (lp->ll_range && !lp->ll_empty2) 2111 clear_tv(&var2);
2120 clear_tv(&var2);
2121 if (!quiet) 2112 if (!quiet)
2122 EMSGN(_(e_listidx), lp->ll_n1); 2113 EMSGN(_(e_listidx), lp->ll_n1);
2123 return NULL; 2114 return NULL;
2124 } 2115 }
2125 2116
2159 2150
2160 lp->ll_tv = &lp->ll_li->li_tv; 2151 lp->ll_tv = &lp->ll_li->li_tv;
2161 } 2152 }
2162 } 2153 }
2163 2154
2155 clear_tv(&var1);
2164 return p; 2156 return p;
2165 } 2157 }
2166 2158
2167 /* 2159 /*
2168 * Clear lval "lp" that was filled by get_lval(). 2160 * Clear lval "lp" that was filled by get_lval().