eval/typval,tests: Fix extending list with itself, add tests

Adds unit test for tv_list_extend and regression test for extend() VimL
function.
This commit is contained in:
ZyX
2016-09-24 00:51:34 +03:00
parent 56e4c2f67e
commit 7ceebacb3f
4 changed files with 187 additions and 27 deletions

View File

@@ -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);
}
}