mirror of
https://github.com/neovim/neovim.git
synced 2025-09-10 21:38:19 +00:00
vim-patch:8.2.3449: sort fails if the sort compare function returns 999 (#17909)
Problem: Sort fails if the sort compare function returns 999.
Solution: Adjust value to -1 / 0 / 1. (Yasuhiro Matsumoto, closes vim/vim#8884)
c04f62346b
This commit is contained in:
@@ -9466,6 +9466,11 @@ static int item_compare2(const void *s1, const void *s2, bool keep_zero)
|
|||||||
res = ITEM_COMPARE_FAIL;
|
res = ITEM_COMPARE_FAIL;
|
||||||
} else {
|
} else {
|
||||||
res = tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err);
|
res = tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err);
|
||||||
|
if (res > 0) {
|
||||||
|
res = 1;
|
||||||
|
} else if (res < 0) {
|
||||||
|
res = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (sortinfo->item_compare_func_err) {
|
if (sortinfo->item_compare_func_err) {
|
||||||
res = ITEM_COMPARE_FAIL; // return value has wrong type
|
res = ITEM_COMPARE_FAIL; // return value has wrong type
|
||||||
|
@@ -59,6 +59,7 @@ endfunc
|
|||||||
func Test_sort_numbers()
|
func Test_sort_numbers()
|
||||||
call assert_equal([3, 13, 28], sort([13, 28, 3], 'N'))
|
call assert_equal([3, 13, 28], sort([13, 28, 3], 'N'))
|
||||||
call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N'))
|
call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N'))
|
||||||
|
call assert_equal([3997, 4996], sort([4996, 3997], 'Compare1'))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_sort_float()
|
func Test_sort_float()
|
||||||
|
Reference in New Issue
Block a user