changeset 25828:14954a7e7c6d v8.2.3449

patch 8.2.3449: sort fails if the sort compare function returns 999 Commit: https://github.com/vim/vim/commit/c04f62346bfd6b92151908239a3c5ab1a7d18f2a Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> Date: Sun Sep 19 17:01:39 2021 +0200 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 https://github.com/vim/vim/issues/8884)
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Sep 2021 17:15:04 +0200
parents cf5792551408
children 7f4f44c01742
files src/list.c src/testdir/test_sort.vim src/version.c
diffstat 3 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/list.c
+++ b/src/list.c
@@ -1945,7 +1945,13 @@ item_compare2(const void *s1, const void
     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);
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -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()
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3449,
+/**/
     3448,
 /**/
     3447,