https://github.com/python/cpython/commit/14641b0badff11e2f90a4e8839287d8c2872bad8
commit: 14641b0badff11e2f90a4e8839287d8c2872bad8
branch: main
author: Neel Somani <[email protected]>
committer: vstinner <[email protected]>
date: 2026-10-05T17:39:11+02:00
summary:

gh-158486: Fix PowerSort mask calculation for very large lists (#158487)

files:
A 
Misc/NEWS.d/next/Core_and_Builtins/2026-09-30-01-30-58.gh-issue-158486.cqmMwv.rst
M Objects/listobject.c

diff --git 
a/Misc/NEWS.d/next/Core_and_Builtins/2026-09-30-01-30-58.gh-issue-158486.cqmMwv.rst
 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-30-01-30-58.gh-issue-158486.cqmMwv.rst
new file mode 100644
index 00000000000000..6ef73833fcdb76
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-30-01-30-58.gh-issue-158486.cqmMwv.rst
@@ -0,0 +1,2 @@
+Fix the PowerSort mask calculation in :meth:`list.sort` for very large
+lists.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 81eb3e1102159b..962ed70aed6b8d 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2263,7 +2263,7 @@ merge_init(MergeState *ms, Py_ssize_t list_size, int 
has_keyfunc,
     while (list_size >> ms->mr_e >= MAX_MINRUN) {
         ++ms->mr_e;
     }
-    ms->mr_mask = (1 << ms->mr_e) - 1;
+    ms->mr_mask = ((Py_ssize_t)1 << ms->mr_e) - 1;
     ms->mr_current = 0;
 }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to