Avoid possible undefined behaviour from signed overflow.

This commit is contained in:
Mark Dickinson 2010-06-11 16:56:34 +00:00
parent 1c164a6f85
commit ab4096f2f9
2 changed files with 11 additions and 3 deletions

View file

@ -506,6 +506,11 @@ class StructTest(unittest.TestCase):
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
def test_count_overflow(self):
hugecount = '{}b'.format(sys.maxsize+1)
self.assertRaises(struct.error, struct.calcsize, hugecount)
if IS32BIT:
def test_crasher(self):
self.assertRaises(MemoryError, struct.pack, "357913941b", "a")