]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix a compiler warning in _randommodule.c (#141058)
authorVictor Stinner <vstinner@python.org>
Wed, 5 Nov 2025 18:00:32 +0000 (19:00 +0100)
committerGitHub <noreply@github.com>
Wed, 5 Nov 2025 18:00:32 +0000 (18:00 +0000)
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

Modules/_randommodule.c

index aa2fd28c232f287c094ffcef232a4ef2ab162d80..544e636d18fede9a2cafec5a9f8413b7c0253ff0 100644 (file)
@@ -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();