← index #7712Issue #1965
Related · high · value 0.673
QUERY · ISSUE

bytearray(length) does not validate length is >= 0

openby dhalbertopened 2021-08-26updated 2021-08-28
py-core
>>> bytearray(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError: memory allocation failed, allocating 4294967295 bytes

This is pretty minor, since it does raise an error. CPython raises a ValueError instead:

>>> bytearray(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: negative count
CANDIDATE · ISSUE

bytearray extended when append has exception thrown

closedby ryannathansopened 2016-04-05updated 2016-04-07

a = bytearray(1000)
a.append(bytearray(10))

An exception occurs here (expected behavior)

len(a)

The length has changed as a result of the exception.

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