Commit 1f953176 authored by Jeroen Demeyer's avatar Jeroen Demeyer Committed by Gregory P. Smith

bpo-37138: fix undefined behaviour with memcpy() on NULL array (GH-13867)

parent e7e5039d
...@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args, ...@@ -71,7 +71,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
} }
/* use borrowed references */ /* use borrowed references */
newargs[0] = self; newargs[0] = self;
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *)); if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
* NULL and calling memcpy() with a NULL pointer
* is undefined behaviour. */
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
}
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames); result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
PyMem_Free(newargs); PyMem_Free(newargs);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment