mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
Issue #27870: A left shift of zero by a large integer no longer attempts to allocate large amounts of memory.
This commit is contained in:
parent
4e1de16f88
commit
82a95277b8
3 changed files with 23 additions and 0 deletions
|
@ -878,6 +878,21 @@ class LongTest(unittest.TestCase):
|
|||
self.check_truediv(-x, y)
|
||||
self.check_truediv(-x, -y)
|
||||
|
||||
def test_lshift_of_zero(self):
|
||||
self.assertEqual(0 << 0, 0)
|
||||
self.assertEqual(0 << 10, 0)
|
||||
with self.assertRaises(ValueError):
|
||||
0 << -1
|
||||
|
||||
@support.cpython_only
|
||||
def test_huge_lshift_of_zero(self):
|
||||
# Shouldn't try to allocate memory for a huge shift. See issue #27870.
|
||||
# Other implementations may have a different boundary for overflow,
|
||||
# or not raise at all.
|
||||
self.assertEqual(0 << sys.maxsize, 0)
|
||||
with self.assertRaises(OverflowError):
|
||||
0 << (sys.maxsize + 1)
|
||||
|
||||
def test_small_ints(self):
|
||||
for i in range(-5, 257):
|
||||
self.assertIs(i, i + 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue