Bug description:
Since gh-156865, adding a value that does not fit to an 'f', 'Zf' or 'e' array raises OverflowError, but append(), insert() and extend() still grow the array by one item. append() and extend() leave an item read from uninitialized memory, and insert() duplicates the neighbouring item.
import array
for method, args in [('append', (1e300,)), ('insert', (0, 1e300))]:
a = array.array('f', [1.0])
try:
getattr(a, method)(*args)
except OverflowError as e:
print(f'{method}: {e}: {a}')
Output on a debug build of main:
append: float too large to pack with f format: array('f', [1.0, -431602080.0])
insert: float too large to pack with f format: array('f', [1.0, 1.0])
Expected: array('f', [1.0]) in both cases. 3.15 has the same problem for 'e' arrays with values such as 123456.0.
CPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs
Bug description:
Since gh-156865, adding a value that does not fit to an
'f','Zf'or'e'array raisesOverflowError, butappend(),insert()andextend()still grow the array by one item.append()andextend()leave an item read from uninitialized memory, andinsert()duplicates the neighbouring item.Output on a debug build of main:
Expected:
array('f', [1.0])in both cases. 3.15 has the same problem for'e'arrays with values such as123456.0.CPython versions tested on:
3.15, CPython main branch
Operating systems tested on:
Linux
Linked PRs