comparison src/dict.c @ 23458:d2b1269c2c68 v8.2.2272

patch 8.2.2272: Vim9: extend() can violate the type of a variable Commit: https://github.com/vim/vim/commit/aa210a3aeccc33c6051978017959126b037f94af Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 2 15:41:03 2021 +0100 patch 8.2.2272: Vim9: extend() can violate the type of a variable Problem: Vim9: extend() can violate the type of a variable. Solution: Add the type to the dictionary or list and check items against it. (closes #7593)
author Bram Moolenaar <Bram@vim.org>
date Sat, 02 Jan 2021 15:45:04 +0100
parents 657216220293
children 6bfb302d8392
comparison
equal deleted inserted replaced
23457:86b9697a8c63 23458:d2b1269c2c68
105 */ 105 */
106 void 106 void
107 dict_free_contents(dict_T *d) 107 dict_free_contents(dict_T *d)
108 { 108 {
109 hashtab_free_contents(&d->dv_hashtab); 109 hashtab_free_contents(&d->dv_hashtab);
110 free_type(d->dv_type);
111 d->dv_type = NULL;
110 } 112 }
111 113
112 /* 114 /*
113 * Clear hashtab "ht" and dict items it contains. 115 * Clear hashtab "ht" and dict items it contains.
114 * If "ht" is not freed then you should call hash_init() next! 116 * If "ht" is not freed then you should call hash_init() next!
1055 { 1057 {
1056 dictitem_T *di1; 1058 dictitem_T *di1;
1057 hashitem_T *hi2; 1059 hashitem_T *hi2;
1058 int todo; 1060 int todo;
1059 char_u *arg_errmsg = (char_u *)N_("extend() argument"); 1061 char_u *arg_errmsg = (char_u *)N_("extend() argument");
1062 type_T *type;
1063
1064 if (d1->dv_type != NULL && d1->dv_type->tt_member != NULL)
1065 type = d1->dv_type->tt_member;
1066 else
1067 type = NULL;
1060 1068
1061 todo = (int)d2->dv_hashtab.ht_used; 1069 todo = (int)d2->dv_hashtab.ht_used;
1062 for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2) 1070 for (hi2 = d2->dv_hashtab.ht_array; todo > 0; ++hi2)
1063 { 1071 {
1064 if (!HASHITEM_EMPTY(hi2)) 1072 if (!HASHITEM_EMPTY(hi2))
1074 && var_wrong_func_name(hi2->hi_key, di1 == NULL)) 1082 && var_wrong_func_name(hi2->hi_key, di1 == NULL))
1075 break; 1083 break;
1076 if (!valid_varname(hi2->hi_key, TRUE)) 1084 if (!valid_varname(hi2->hi_key, TRUE))
1077 break; 1085 break;
1078 } 1086 }
1087
1088 if (type != NULL
1089 && check_typval_type(type, &HI2DI(hi2)->di_tv, 0) == FAIL)
1090 break;
1091
1079 if (di1 == NULL) 1092 if (di1 == NULL)
1080 { 1093 {
1081 di1 = dictitem_copy(HI2DI(hi2)); 1094 di1 = dictitem_copy(HI2DI(hi2));
1082 if (di1 != NULL && dict_add(d1, di1) == FAIL) 1095 if (di1 != NULL && dict_add(d1, di1) == FAIL)
1083 dictitem_free(di1); 1096 dictitem_free(di1);