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)
diff --git a/src/list.c b/src/list.c
index 1c41f07..56ee5a5 100644
--- a/src/list.c
+++ b/src/list.c
@@ -270,6 +270,7 @@
if (l->lv_used_next != NULL)
l->lv_used_next->lv_used_prev = l->lv_used_prev;
+ free_type(l->lv_type);
vim_free(l);
}
@@ -689,13 +690,17 @@
/*
* Insert typval_T "tv" in list "l" before "item".
* If "item" is NULL append at the end.
- * Return FAIL when out of memory.
+ * Return FAIL when out of memory or the type is wrong.
*/
int
list_insert_tv(list_T *l, typval_T *tv, listitem_T *item)
{
- listitem_T *ni = listitem_alloc();
+ listitem_T *ni;
+ if (l->lv_type != NULL && l->lv_type->tt_member != NULL
+ && check_typval_type(l->lv_type->tt_member, tv, 0) == FAIL)
+ return FAIL;
+ ni = listitem_alloc();
if (ni == NULL)
return FAIL;
copy_tv(tv, &ni->li_tv);