]> granicus.if.org Git - python/commitdiff
_PyLong_Copy(): was creating a copy of the absolute value, but should
authorTim Peters <tim.peters@gmail.com>
Sat, 2 Mar 2002 04:18:04 +0000 (04:18 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 2 Mar 2002 04:18:04 +0000 (04:18 +0000)
copy the sign too.  Added a test to test_descr to ensure that it does.

Bugfix candidate.

Lib/test/test_descr.py
Objects/longobject.c

index e667efb18af72c6f4e8bb75a5e9e2d84e14a0228..de9bba163660a0d4890a268bd4d2d54493ce9bd0 100644 (file)
@@ -1751,6 +1751,7 @@ def inherits():
     # Check that negative clones don't segfault
     a = longclone(-1)
     vereq(a.__dict__, {})
+    vereq(long(a), -1)  # verify PyNumber_Long() copies the sign bit
 
     class precfloat(float):
         __slots__ = ['prec']
index 5b7a00aa9fcf817b66f1fb1a6e753e10c07453aa..f3e7df7134285eb1757bfd14845f95ab21126f98 100644 (file)
@@ -63,7 +63,7 @@ _PyLong_Copy(PyLongObject *src)
                i = -(i);
        result = _PyLong_New(i);
        if (result != NULL) {
-               result->ob_size = i;
+               result->ob_size = src->ob_size;
                while (--i >= 0)
                        result->ob_digit[i] = src->ob_digit[i];
        }