diff options
-rw-r--r-- | src/nvim/eval.c | 8 | ||||
-rw-r--r-- | test/functional/eval/null_spec.lua | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c654fe691e..064f2c072c 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15232,6 +15232,8 @@ item_compare_end: // When the result would be zero, compare the item indexes. Makes the // sort stable. if (res == 0 && !keep_zero) { + // WARNING: When using uniq si1 and si2 are actually listitem_T **, no + // indexes are there. res = si1->idx > si2->idx ? 1 : -1; } return res; @@ -15297,6 +15299,8 @@ static int item_compare2(const void *s1, const void *s2, bool keep_zero) // When the result would be zero, compare the pointers themselves. Makes // the sort stable. if (res == 0 && !keep_zero) { + // WARNING: When using uniq si1 and si2 are actually listitem_T **, no + // indexes are there. res = si1->idx > si2->idx ? 1 : -1; } @@ -15337,7 +15341,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) } else { list_T *const l = argvars[0].vval.v_list; if (tv_check_lock(tv_list_locked(l), arg_errmsg, TV_TRANSLATE)) { - goto theend; + goto theend; } rettv->vval.v_list = l; rettv->v_type = VAR_LIST; @@ -15462,7 +15466,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) listitem_T *prev_li = NULL; TV_LIST_ITER(l, li, { if (prev_li != NULL) { - if (item_compare_func_ptr(prev_li, li) == 0) { + if (item_compare_func_ptr(&prev_li, &li) == 0) { ptrs[i++].item = prev_li; } if (info.item_compare_func_err) { diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 1c1dd6fd79..64be8fcd11 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -102,6 +102,8 @@ describe('NULL', function() 'E742: Cannot change value of reverse() argument', 0) null_expr_test('makes sort() error out', 'sort(L)', 'E742: Cannot change value of sort() argument', 0) + null_expr_test('makes uniq() error out', 'uniq(L)', + 'E742: Cannot change value of uniq() argument', 0) null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) null_expr_test('makes join() return empty string', 'join(L, "")', 0, '') |