Skip to content

Commit da86200

Browse files
committed
Avoid undefined behavior: memset() with size=0
1 parent db8eb51 commit da86200

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎Objects/listobject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4449,7 +4449,9 @@ PyListWriter_Create(Py_ssize_t size)
44494449
#ifdef Py_DEBUG
44504450
// In debug mode, set all items to NULL to be able to check that they are
44514451
// non-NULL in PyListWriter_Finish().
4452-
memset(_PyList_CAST(list)->ob_item, 0, size * sizeof(PyObject*));
4452+
if (1 <= size) {
4453+
memset(_PyList_CAST(list)->ob_item, 0, size * sizeof(PyObject*));
4454+
}
44534455
#endif
44544456

44554457
PyListWriter *writer = (PyListWriter*)list;

0 commit comments

Comments
 (0)