https://github.com/python/cpython/commit/4ac16dd10950fad2d3e58e8b0ba5f2e621af3cc1
commit: 4ac16dd10950fad2d3e58e8b0ba5f2e621af3cc1
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-11-05T18:00:32Z
summary:

Fix a compiler warning in _randommodule.c (#141058)

The test just before the cast ensures that the cast cannot overflow.

Fix the warning on 32-bit Windows:

    Modules\_randommodule.c(525,28): warning C4244: '=': conversion
    from 'uint64_t' to 'Py_ssize_t', possible loss of data

files:
M Modules/_randommodule.c

diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index aa2fd28c232f28..544e636d18fede 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -522,7 +522,7 @@ _random_Random_getrandbits_impl(RandomObject *self, 
uint64_t k)
         PyErr_NoMemory();
         return NULL;
     }
-    words = (k - 1u) / 32u + 1u;
+    words = (Py_ssize_t)((k - 1u) / 32u + 1u);
     wordarray = (uint32_t *)PyMem_Malloc(words * 4);
     if (wordarray == NULL) {
         PyErr_NoMemory();

_______________________________________________
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