Mercurial > vim
comparison src/list.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 | b545334ae654 |
children | 1bb7fa4f9b35 |
comparison
equal
deleted
inserted
replaced
23457:86b9697a8c63 | 23458:d2b1269c2c68 |
---|---|
268 else | 268 else |
269 l->lv_used_prev->lv_used_next = l->lv_used_next; | 269 l->lv_used_prev->lv_used_next = l->lv_used_next; |
270 if (l->lv_used_next != NULL) | 270 if (l->lv_used_next != NULL) |
271 l->lv_used_next->lv_used_prev = l->lv_used_prev; | 271 l->lv_used_next->lv_used_prev = l->lv_used_prev; |
272 | 272 |
273 free_type(l->lv_type); | |
273 vim_free(l); | 274 vim_free(l); |
274 } | 275 } |
275 | 276 |
276 void | 277 void |
277 list_free_items(int copyID) | 278 list_free_items(int copyID) |
687 } | 688 } |
688 | 689 |
689 /* | 690 /* |
690 * Insert typval_T "tv" in list "l" before "item". | 691 * Insert typval_T "tv" in list "l" before "item". |
691 * If "item" is NULL append at the end. | 692 * If "item" is NULL append at the end. |
692 * Return FAIL when out of memory. | 693 * Return FAIL when out of memory or the type is wrong. |
693 */ | 694 */ |
694 int | 695 int |
695 list_insert_tv(list_T *l, typval_T *tv, listitem_T *item) | 696 list_insert_tv(list_T *l, typval_T *tv, listitem_T *item) |
696 { | 697 { |
697 listitem_T *ni = listitem_alloc(); | 698 listitem_T *ni; |
698 | 699 |
700 if (l->lv_type != NULL && l->lv_type->tt_member != NULL | |
701 && check_typval_type(l->lv_type->tt_member, tv, 0) == FAIL) | |
702 return FAIL; | |
703 ni = listitem_alloc(); | |
699 if (ni == NULL) | 704 if (ni == NULL) |
700 return FAIL; | 705 return FAIL; |
701 copy_tv(tv, &ni->li_tv); | 706 copy_tv(tv, &ni->li_tv); |
702 list_insert(l, ni, item); | 707 list_insert(l, ni, item); |
703 return OK; | 708 return OK; |