From: Tim Peters Date: Wed, 13 Jun 2001 20:50:08 +0000 (+0000) Subject: _PyLong_AsByteArray: added assert that the input is normalized. This is X-Git-Tag: v2.2a3~1559 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=898cf85c25de57a0c40bd9bedc00519674d09457;p=thirdparty%2FPython%2Fcpython.git _PyLong_AsByteArray: added assert that the input is normalized. This is outside the function's control, but is crucial to correct operation. --- diff --git a/Objects/longobject.c b/Objects/longobject.c index 3c22470fb0d1..f8a912940a94 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -358,7 +358,11 @@ _PyLong_AsByteArray(PyLongObject* v, pincr = -1; } - /* Copy over all the Python digits. */ + /* Copy over all the Python digits. + It's crucial that every Python digit except for the MSD contribute + exactly SHIFT bits to the total, so first assert that the long is + normalized. */ + assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0); j = 0; accum = 0; accumbits = 0;