0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.3449: sort fails if the sort compare function returns 999

Problem:    Sort fails if the sort compare function returns 999.
Solution:   Adjust value to -1 / 0 / 1. (Yasuhiro Matsumoto, closes #8884)
This commit is contained in:
Yasuhiro Matsumoto 2021-09-19 17:01:39 +02:00 committed by Bram Moolenaar
parent 1d34189ecb
commit c04f62346b
3 changed files with 9 additions and 0 deletions

View File

@ -1945,7 +1945,13 @@ item_compare2(const void *s1, const void *s2)
if (res == FAIL)
res = ITEM_COMPARE_FAIL;
else
{
res = (int)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)
res = ITEM_COMPARE_FAIL; // return value has wrong type
clear_tv(&rettv);

View File

@ -58,6 +58,7 @@ endfunc
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([3997, 4996], sort([4996, 3997], 'Compare1'))
endfunc
func Test_sort_float()

View File

@ -757,6 +757,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3449,
/**/
3448,
/**/