diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-07-18 22:25:29 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-18 22:25:29 +0200 |
commit | 885971e2f5eabc4108e083086c1d6d0a31a2782f (patch) | |
tree | 4ecfebdc5ea8ca8c6274b76255bc06c007f9a440 /src/list.c | |
parent | 9ff9c7b9741b216d3dc75603e50654088dc5f55b (diff) |
patch 8.2.3182: Vim9: crash when using removing items from a constant listv8.2.3182
Problem: Vim9: crash when using removing items from a constant list.
(Yegappan Lakshmanan)
Solution: When a list was allocated with items copy them.
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/list.c b/src/list.c index d138d868cd..417f735e0d 100644 --- a/src/list.c +++ b/src/list.c @@ -1566,12 +1566,32 @@ list_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg) vimlist_remove(l, item, item2); if (rettv_list_alloc(rettv) == OK) { - l = rettv->vval.v_list; - l->lv_first = item; - l->lv_u.mat.lv_last = item2; - item->li_prev = NULL; - item2->li_next = NULL; - l->lv_len = cnt; + list_T *rl = rettv->vval.v_list; + + if (l->lv_with_items > 0) + { + // need to copy the list items and move the value + while (item != NULL) + { + li = listitem_alloc(); + if (li == NULL) + return; + li->li_tv = item->li_tv; + init_tv(&item->li_tv); + list_append(rl, li); + if (item == item2) + break; + item = item->li_next; + } + } + else + { + rl->lv_first = item; + rl->lv_u.mat.lv_last = item2; + item->li_prev = NULL; + item2->li_next = NULL; + rl->lv_len = cnt; + } } } } |