diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst
new file mode 100644
index 0000000000000000000000000000000000000000..4fd0532e827d1862013de117917e077c53a57630
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-18-08-47-40.gh-issue-96821.Co2iOq.rst	
@@ -0,0 +1 @@
+Fix undefined behaviour in ``_testcapimodule.c``.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1a3cbe0b212aa693f22357225d9a8948016263a5..43fec8138a0ebc261934942584b92ab46077a115 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -5576,8 +5576,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);
 }