diff Lib/test/test_long.py @ 76440:cdcc6b489862 3.2

Issue #14630: Fix an incorrect access of ob_digit[0] for a zero instance of an int subclass.
author Mark Dickinson <mdickinson@enthought.com>
date Fri, 20 Apr 2012 21:42:49 +0100
parents 3c9232a684ae
children c7b0f711dc15
line wrap: on
line diff
--- a/Lib/test/test_long.py	Fri Apr 20 14:36:47 2012 +0200
+++ b/Lib/test/test_long.py	Fri Apr 20 21:42:49 2012 +0100
@@ -1148,6 +1148,20 @@
         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)