← index #5427Issue #2114
Off-topic · high · value 1.098
QUERY · ISSUE

struct.pack doesn't check for value bounds

openby dimpoloopened 2019-12-16updated 2019-12-19
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 · ISSUE

feature regression: struct packing zero length throws exception

closedby ryannathansopened 2016-05-27updated 2016-05-28

Python3.5

>>> import struct
>>> struct.pack("0s", bytearray(0))
b''

Micropython

>>> import struct
>>> struct.pack("0s", bytearray(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied