From af9046193148084f008501434e4c9f49fedc053f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 17 Jan 2017 22:50:20 +0300 Subject: py/binary: mp_binary_get_size: Raise error on unsupported typecodes. Previouly, we had errors checked in callers, which led to duplicate code or missing checks in some places. --- tests/basics/struct2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests/basics/struct2.py') diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py index 6dd963260b..e3f8bbebfb 100644 --- a/tests/basics/struct2.py +++ b/tests/basics/struct2.py @@ -26,7 +26,17 @@ print(struct.calcsize('0s1s0H2H')) print(struct.unpack('<0s1s0H2H', b'01234')) print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515)) -# check that zero of an unknown type raises an exception +# check that unknown types raise an exception +try: + struct.unpack('z', b'1') +except: + print('Exception') + +try: + struct.pack('z', (b'1',)) +except: + print('Exception') + try: struct.calcsize('0z') except: -- cgit v1.2.3