Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix incorrect PyObject_CallFunction usage (remove extra NULL argument)
This PR fixes incorrect calls to PyObject_CallFunction where an
extra NULL argument was passed despite the format string already
specifying the complete argument list.
PyObject_CallFunction does not use a NULL terminator; it relies
solely on the format string to determine how many arguments to read.
Providing more arguments than required results in undefined behavior
due to va_list misalignment.

The affected calls:
- PyImport_Import() — "OOOOi" was given 6 arguments instead of 5
- deque_copy() — "Oi" was given 3 arguments instead of 2

Both have been corrected by removing the superfluous NULL.
No functional changes beyond fixing the API misuse.

Signed-off-by: Yongtao Huang <[email protected]>
  • Loading branch information
hyongtao-code committed Dec 11, 2025
commit be078a12d49f59522faf8a593226f860bc5de1c2
2 changes: 1 addition & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ deque_copy_impl(dequeobject *deque)
(PyObject *)deque);
else
result = PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
deque, old_deque->maxlen, NULL);
deque, old_deque->maxlen);
if (result != NULL && !PyObject_TypeCheck(result, state->deque_type)) {
PyErr_Format(PyExc_TypeError,
"%.200s() must return a deque, not %.200s",
Expand Down
2 changes: 1 addition & 1 deletion Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -4067,7 +4067,7 @@ PyImport_Import(PyObject *module_name)
Always use absolute import here.
Calling for side-effect of import. */
r = PyObject_CallFunction(import, "OOOOi", module_name, globals,
globals, from_list, 0, NULL);
globals, from_list, 0);
if (r == NULL)
goto err;
Py_DECREF(r);
Expand Down
Loading