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

* gh-96821: Assert for demonstrating undefined behaviour

* Fix UB

(cherry picked from commit cbdeda8ce7)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Matthias Görgens <matthias.goergens@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-09-19 03:20:23 -07:00 committed by GitHub
parent f4be544a03
commit 88a3f1873e
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

@ -5475,8 +5475,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);
}