gh-96821: Fix undefined behaviour in _testcapimodule.c (GH-96915)

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
This commit is contained in:
Matthias Görgens 2022-09-19 15:59:13 +08:00 committed by GitHub
parent bbc24b2bd5
commit cbdeda8ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix undefined behaviour in ``_testcapimodule.c``.

View File

@ -4918,8 +4918,10 @@ meth_fastcall_keywords(PyObject* self, PyObject* const* args,
if (pyargs == NULL) {
return NULL;
}
assert(args != NULL || nargs == 0);
PyObject* const* args_offset = args == NULL ? NULL : args + nargs;
PyObject *pykwargs = PyObject_Vectorcall((PyObject*)&PyDict_Type,
args + nargs, 0, kwargs);
args_offset, 0, kwargs);
return Py_BuildValue("NNN", _null_to_none(self), pyargs, pykwargs);
}