Mercurial > vim
diff src/list.c @ 22545:47596deedfb5 v8.2.1821
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Commit: https://github.com/vim/vim/commit/1a73923705744ab8297dd856d194e20297563456
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 10 15:37:58 2020 +0200
patch 8.2.1821: Vim9: concatenating to a NULL list doesn't work
Problem: Vim9: concatenating to a NULL list doesn't work.
Solution: Handle a NULL list like an empty list. (closes https://github.com/vim/vim/issues/7064)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Oct 2020 15:45:03 +0200 |
parents | 4ce3906e5997 |
children | f140b9036aa5 |
line wrap: on
line diff
--- a/src/list.c +++ b/src/list.c @@ -824,7 +824,7 @@ f_flatten(typval_T *argvars, typval_T *r } /* - * Extend "l1" with "l2". + * Extend "l1" with "l2". "l1" must not be NULL. * If "bef" is NULL append at the end, otherwise insert before this item. * Returns FAIL when out of memory. */ @@ -832,8 +832,13 @@ f_flatten(typval_T *argvars, typval_T *r list_extend(list_T *l1, list_T *l2, listitem_T *bef) { listitem_T *item; - int todo = l2->lv_len; + int todo; + // NULL list is equivalent to an empty list: nothing to do. + if (l2 == NULL || l2->lv_len == 0) + return OK; + + todo = l2->lv_len; CHECK_LIST_MATERIALIZE(l1); CHECK_LIST_MATERIALIZE(l2); @@ -854,15 +859,17 @@ list_concat(list_T *l1, list_T *l2, typv { list_T *l; - if (l1 == NULL || l2 == NULL) - return FAIL; - // make a copy of the first list. - l = list_copy(l1, FALSE, 0); + if (l1 == NULL) + l = list_alloc(); + else + l = list_copy(l1, FALSE, 0); if (l == NULL) return FAIL; tv->v_type = VAR_LIST; tv->vval.v_list = l; + if (l1 == NULL) + ++l->lv_refcount; // append all items from the second list return list_extend(l, l2, NULL);