Skip to content

Commit 8675f55

Browse files
[3.14] Fix a compiler warning in _randommodule.c (GH-141058) (#141063)
Fix a compiler warning in _randommodule.c (GH-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 (cherry picked from commit 4ac16dd) Co-authored-by: Victor Stinner <[email protected]>
1 parent fa8f464 commit 8675f55

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Modules/_randommodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ _random_Random_getrandbits_impl(RandomObject *self, uint64_t k)
522522
PyErr_NoMemory();
523523
return NULL;
524524
}
525-
words = (k - 1u) / 32u + 1u;
525+
words = (Py_ssize_t)((k - 1u) / 32u + 1u);
526526
wordarray = (uint32_t *)PyMem_Malloc(words * 4);
527527
if (wordarray == NULL) {
528528
PyErr_NoMemory();

0 commit comments

Comments
 (0)