Skip to content

Commit c04f623

Browse files
mattnbrammool
authored andcommitted
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)
1 parent 1d34189 commit c04f623

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/list.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,13 @@ item_compare2(const void *s1, const void *s2)
19451945
if (res == FAIL)
19461946
res = ITEM_COMPARE_FAIL;
19471947
else
1948+
{
19481949
res = (int)tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err);
1950+
if (res > 0)
1951+
res = 1;
1952+
else if (res < 0)
1953+
res = -1;
1954+
}
19491955
if (sortinfo->item_compare_func_err)
19501956
res = ITEM_COMPARE_FAIL; // return value has wrong type
19511957
clear_tv(&rettv);

src/testdir/test_sort.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ endfunc
5858
func Test_sort_numbers()
5959
call assert_equal([3, 13, 28], sort([13, 28, 3], 'N'))
6060
call assert_equal(['3', '13', '28'], sort(['13', '28', '3'], 'N'))
61+
call assert_equal([3997, 4996], sort([4996, 3997], 'Compare1'))
6162
endfunc
6263

6364
func Test_sort_float()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,8 @@ static char *(features[]) =
757757

758758
static int included_patches[] =
759759
{ /* Add new patch number below this line */
760+
/**/
761+
3449,
760762
/**/
761763
3448,
762764
/**/

0 commit comments

Comments
 (0)