patch 9.1.1955: sort() does not handle large numbers correctly

Commit: 
https://github.com/vim/vim/commit/04794efe12863eb96a489531c299879e6c8d15d4
Author: Yegappan Lakshmanan <[email protected]>
Date:   Sat Dec 6 10:22:07 2025 +0100

    patch 9.1.1955: sort() does not handle large numbers correctly
    
    Problem:  sort() does not handle large numbers correctly
              (Igbanam Ogbuluijah)
    Solution: Don't truncate the return value of tv_get_number_chk()
              (Yegappan Lakshmanan)
    
    closes: #18868
    
    Signed-off-by: Yegappan Lakshmanan <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/list.c b/src/list.c
index f8c365af8..7d6793c59 100644
--- a/src/list.c
+++ b/src/list.c
@@ -2083,11 +2083,10 @@ item_compare2(const void *s1, const void *s2)
        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;
+       varnumber_T     n;
+
+       n = tv_get_number_chk(&rettv, &sortinfo->item_compare_func_err);
+       res = (n > 0) ? 1 : (n < 0) ? -1 : 0;
     }
     if (sortinfo->item_compare_func_err)
        res = ITEM_COMPARE_FAIL;  // return value has wrong type
diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim
index 60b021242..39c4114f0 100644
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -1,5 +1,7 @@
 " Tests for the "sort()" function and for the ":sort" command.
 
+import './util/vim9.vim' as v9
+
 func Compare1(a, b) abort
   call sort(range(3), 'Compare2')
   return a:a - a:b
@@ -1557,4 +1559,30 @@ func Test_sort_using_dict_func()
   delfunc DictSort
 endfunc
 
+" Test for using sort() function with a funcref and large numbers
+func Test_sort_funcref_with_large_number()
+  let lines =<< trim END
+    call assert_equal(
+        \ [
+        \  (188325333471071, 188931909913550),
+        \  (229539777187355, 229539777187355),
+        \  (245727634348687, 249469249579525),
+        \  (264028451845520, 265514296554744),
+        \  (375117820166731, 378942174241518),
+        \  (487766135067138, 491977135306566),
+        \  (535474757750378, 535849288071548)
+        \ ],
+        \ [
+        \  (229539777187355, 229539777187355),
+        \  (487766135067138, 491977135306566),
+        \  (188325333471071, 188931909913550),
+        \  (264028451845520, 265514296554744),
+        \  (245727634348687, 249469249579525),
+        \  (375117820166731, 378942174241518),
+        \  (535474757750378, 535849288071548)
+        \ ]->sort(LSTART a, b LMIDDLE a[0] - b[0] LEND))
+  END
+  call v9.CheckSourceLegacyAndVim9Success(lines)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index bb964b62a..3df7fce94 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1955,
 /**/
     1954,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1vRoc9-001Raa-Ny%40256bit.org.

Raspunde prin e-mail lui