aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-09-24 00:51:34 +0300
committerZyX <kp-pav@yandex.ru>2017-03-29 10:08:06 +0300
commit7ceebacb3fad49ba8321397cf839948caa55b3f5 (patch)
tree4c7179f83001d9c7f0b25045e6779bc8df26b81e /src
parent56e4c2f67e54b88f637d30e565313bc6b2c22f29 (diff)
downloadrneovim-7ceebacb3fad49ba8321397cf839948caa55b3f5.tar.gz
rneovim-7ceebacb3fad49ba8321397cf839948caa55b3f5.tar.bz2
rneovim-7ceebacb3fad49ba8321397cf839948caa55b3f5.zip
eval/typval,tests: Fix extending list with itself, add tests
Adds unit test for tv_list_extend and regression test for extend() VimL function.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/typval.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c
index 1cc195ddc4..746cbbfe1c 100644
--- a/src/nvim/eval/typval.c
+++ b/src/nvim/eval/typval.c
@@ -479,11 +479,13 @@ void tv_list_extend(list_T *const l1, list_T *const l2,
FUNC_ATTR_NONNULL_ARG(1, 2)
{
int todo = l2->lv_len;
+ listitem_T *const befbef = (bef == NULL ? NULL : bef->li_prev);
+ listitem_T *const saved_next = (befbef == NULL ? NULL : befbef->li_next);
// We also quit the loop when we have inserted the original item count of
// the list, avoid a hang when we extend a list with itself.
for (listitem_T *item = l2->lv_first
; item != NULL && --todo >= 0
- ; item = item->li_next) {
+ ; item = (item == befbef ? saved_next : item->li_next)) {
tv_list_insert_tv(l1, &item->li_tv, bef);
}
}