]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_PyLong_AsByteArray: added assert that the input is normalized. This is
authorTim Peters <tim.peters@gmail.com>
Wed, 13 Jun 2001 20:50:08 +0000 (20:50 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 13 Jun 2001 20:50:08 +0000 (20:50 +0000)
outside the function's control, but is crucial to correct operation.

Objects/longobject.c

index 3c22470fb0d1cd041fa9298455f3603b0400739f..f8a912940a94415f4513c7adec38b407e076dfa9 100644 (file)
@@ -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;