Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 898cf85

Browse files
committed
_PyLong_AsByteArray: added assert that the input is normalized. This is
outside the function's control, but is crucial to correct operation.
1 parent 9cb0c38 commit 898cf85

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Objects/longobject.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ _PyLong_AsByteArray(PyLongObject* v,
358358
pincr = -1;
359359
}
360360

361-
/* Copy over all the Python digits. */
361+
/* Copy over all the Python digits.
362+
It's crucial that every Python digit except for the MSD contribute
363+
exactly SHIFT bits to the total, so first assert that the long is
364+
normalized. */
365+
assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
362366
j = 0;
363367
accum = 0;
364368
accumbits = 0;

0 commit comments

Comments
 (0)