@@ -62,9 +62,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
6262 }
6363 else {
6464 Py_ssize_t nkwargs = (kwnames == NULL ) ? 0 : PyTuple_GET_SIZE (kwnames );
65- PyObject * * newargs ;
6665 Py_ssize_t totalargs = nargs + nkwargs ;
66+ if (totalargs == 0 ) {
67+ return _PyObject_Vectorcall (func , & self , 1 , NULL );
68+ }
69+
6770 PyObject * newargs_stack [_PY_FASTCALL_SMALL_STACK ];
71+ PyObject * * newargs ;
6872 if (totalargs <= (Py_ssize_t )Py_ARRAY_LENGTH (newargs_stack ) - 1 ) {
6973 newargs = newargs_stack ;
7074 }
@@ -77,11 +81,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
7781 }
7882 /* use borrowed references */
7983 newargs [0 ] = self ;
80- if ( totalargs ) { /* bpo-37138: if totalargs == 0, then args may be
81- * NULL and calling memcpy() with a NULL pointer
82- * is undefined behaviour. */
83- memcpy ( newargs + 1 , args , totalargs * sizeof ( PyObject * ) );
84- }
84+ /* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
85+ * We need this, since calling memcpy() with a NULL pointer is
86+ * undefined behaviour. */
87+ assert ( args != NULL );
88+ memcpy ( newargs + 1 , args , totalargs * sizeof ( PyObject * ));
8589 result = _PyObject_Vectorcall (func , newargs , nargs + 1 , kwnames );
8690 if (newargs != newargs_stack ) {
8791 PyMem_Free (newargs );
0 commit comments