QUERY · ISSUE
struct.pack doesn't check for value bounds
py-core
Setup: MicroPython v1.11-555-g80df377e9 on 2019-11-04; PYBv1.1 with STM32F405RG
struct.pack('B', 256) # returns b'\x00'
CPython errors out with struct.error: ubyte format requires 0 <= number <= 255
CANDIDATE · PULL REQUEST
py/binary.c: Bugfix for struct.pack('>Q', 16)
Without bugfix:
struct.pack('>Q', 16)
b'\x00\x00\x00\x10\x00\x00\x00\x00'
With bugfix:
struct.pack('>Q', 16)
b'\x00\x00\x00\x00\x00\x00\x00\x10'
Also added test-case to tests/basics/struct1_intbig.py; without this merge-request the test will fail on 32-bit platforms.