summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-04-20 20:42:49 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-04-20 20:42:49 (GMT)
commitbcc17eefd2b630aca2fc0f4e27f274a028030542 (patch)
treecb5ee87cd8a49f2f2a8fc4cac979e4ca35bca81c /Lib/test/test_long.py
parent63674f4b52aa7c2832fec09a026e24cd521e491b (diff)
downloadcpython-bcc17eefd2b630aca2fc0f4e27f274a028030542.zip
cpython-bcc17eefd2b630aca2fc0f4e27f274a028030542.tar.gz
cpython-bcc17eefd2b630aca2fc0f4e27f274a028030542.tar.bz2
Issue #14630: Fix an incorrect access of ob_digit[0] for a zero instance of an int subclass.
Diffstat (limited to 'Lib/test/test_long.py')
-rw-r--r--Lib/test/test_long.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 04066ec..3ebc1f7 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1148,6 +1148,20 @@ class LongTest(unittest.TestCase):
self.assertRaises(TypeError, myint.from_bytes, 0, 'big')
self.assertRaises(TypeError, int.from_bytes, 0, 'big', True)
+ def test_access_to_nonexistent_digit_0(self):
+ # http://bugs.python.org/issue14630: A bug in _PyLong_Copy meant that
+ # ob_digit[0] was being incorrectly accessed for instances of a
+ # subclass of int, with value 0.
+ class Integer(int):
+ def __new__(cls, value=0):
+ self = int.__new__(cls, value)
+ self.foo = 'foo'
+ return self
+
+ integers = [Integer(0) for i in range(1000)]
+ for n in map(int, integers):
+ self.assertEqual(n, 0)
+
def test_main():
support.run_unittest(LongTest)