Skip to content

Commit 9313299

Browse files
committed
Fix undefined behavior in listwriter_extend_array() with nitem=0
1 parent 8404760 commit 9313299

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎Objects/listobject.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,11 @@ listwriter_extend_array(PyListWriter *writer,
46294629
assert(listwriter_check_consistency(writer));
46304630
assert(nitem >= 0);
46314631

4632+
if (nitem == 0) {
4633+
// Fast path. Avoid also memcpy(dst, src, 0) undefined behavior below.
4634+
return 0;
4635+
}
4636+
46324637
PyListObject *list = _PyList_CAST(writer);
46334638
Py_ssize_t size = Py_SIZE(list);
46344639
Py_ssize_t allocated = list->allocated;

0 commit comments

Comments
 (0)