Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion Lib/test/clinic.test
Original file line number Diff line number Diff line change
Expand Up @@ -3781,6 +3781,9 @@ test_vararg_and_posonly(PyObject *module, PyObject *const *args, Py_ssize_t narg
}
a = args[0];
__clinic_args = PyTuple_New(nargs - 1);
if (!__clinic_args) {
goto exit;
}
for (Py_ssize_t i = 0; i < nargs - 1; ++i) {
PyTuple_SET_ITEM(__clinic_args, i, Py_NewRef(args[1 + i]));
}
Expand All @@ -3793,7 +3796,7 @@ exit:

static PyObject *
test_vararg_and_posonly_impl(PyObject *module, PyObject *a, PyObject *args)
/*[clinic end generated code: output=081a953b8cbe7617 input=08dc2bf7afbf1613]*/
/*[clinic end generated code: output=79b75dc07decc8d6 input=08dc2bf7afbf1613]*/

/*[clinic input]
test_vararg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add missing ``NULL`` check for possible allocation failure in ``*args`` parsing in Argument Clinic.
8 changes: 7 additions & 1 deletion Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,12 +962,16 @@ def parser_body(prototype, *fields, declarations=''):
if not new_or_init:
parser_code.append(normalize_snippet("""
%s = PyTuple_New(%s);
if (!%s) {{
goto exit;
}}
for (Py_ssize_t i = 0; i < %s; ++i) {{
PyTuple_SET_ITEM(%s, i, Py_NewRef(args[%d + i]));
}}
""" % (
p.converter.parser_name,
left_args,
p.converter.parser_name,
left_args,
p.converter.parser_name,
max_pos
Expand Down