SF patch 514641 (Naofumi Honda) - Negative ob_size of LongObjects

Due to the bizarre definition of _PyLong_Copy(), creating an instance
of a subclass of long with a negative value could cause core dumps
later on.  Unfortunately it looks like the behavior of _PyLong_Copy()
is quite intentional, so the fix is more work than feels comfortable.

This fix is almost, but not quite, the code that Naofumi Honda added;
in addition, I added a test case.
This commit is contained in:
Guido van Rossum 2002-03-01 22:24:49 +00:00
parent 6f33250ef9
commit 2eb0b87d14
4 changed files with 23 additions and 4 deletions

View file

@ -1748,6 +1748,10 @@ def inherits():
verify((a + 0).__class__ is long)
verify((0 + a).__class__ is long)
# Check that negative clones don't segfault
a = longclone(-1)
vereq(a.__dict__, {})
class precfloat(float):
__slots__ = ['prec']
def __init__(self, value=0.0, prec=12):