Skip to content

Commit d3293fd

Browse files
committed
PyLongWriter_Finish() checks most significant bits
1 parent 4be289e commit d3293fd

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

Objects/longobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6961,15 +6961,16 @@ PyLongWriter_Finish(PyLongWriter *writer)
69616961
#ifdef Py_DEBUG
69626962
// gh-147988: Detect uninitialized digits: long_alloc() fills digits with
69636963
// 0xFF byte pattern. It's posssible because PyLong_BASE is smaller than
6964-
// the maximum value of the C digit type (uint32_t or unsigned short).
6964+
// the maximum value of the C digit type (uint32_t or unsigned short):
6965+
// most significan bits are unused by the API.
69656966
Py_ssize_t ndigits = _PyLong_DigitCount(obj);
69666967
if (ndigits == 0) {
69676968
// Check ob_digit[0] digit for the number zero
69686969
ndigits = 1;
69696970
}
69706971
for (Py_ssize_t i = 0; i < ndigits; i++) {
69716972
digit d = obj->long_value.ob_digit[i];
6972-
if (d >= PyLong_BASE) {
6973+
if (d & ~(digit)PyLong_MASK) {
69736974
Py_DECREF(obj);
69746975
PyErr_Format(PyExc_SystemError,
69756976
"PyLongWriter_Finish: digit %zd is uninitialized",

0 commit comments

Comments
 (0)