summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorcolorfulappl <colorfulappl@qq.com>2022-12-28 01:10:06 (GMT)
committerGitHub <noreply@github.com>2022-12-28 01:10:06 (GMT)
commita3dbd4c70e93260432fc024265fdf9222926fdad (patch)
tree7d53e10dbb04bde4722a399685b491bd66e78d38 /Python
parent18b43cf95f2455b63a6dbefb813f48fa85a07c7b (diff)
downloadcpython-a3dbd4c70e93260432fc024265fdf9222926fdad.zip
cpython-a3dbd4c70e93260432fc024265fdf9222926fdad.tar.gz
cpython-a3dbd4c70e93260432fc024265fdf9222926fdad.tar.bz2
[3.11] gh-64490: Fix bugs in argument clinic varargs processing (GH-32092) (#100368)
(cherry picked from commit 0da728387c99fe6c127b070f2d250dc5bdd62ee5)
Diffstat (limited to 'Python')
-rw-r--r--Python/getargs.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 9d6483f..3105bd5 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -2570,7 +2570,25 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs,
current_arg = NULL;
}
- buf[i + vararg + 1] = current_arg;
+ /* If an arguments is passed in as a keyword argument,
+ * it should be placed before `buf[vararg]`.
+ *
+ * For example:
+ * def f(a, /, b, *args):
+ * pass
+ * f(1, b=2)
+ *
+ * This `buf` array should be: [1, 2, NULL].
+ * In this case, nargs < vararg.
+ *
+ * Otherwise, we leave a place at `buf[vararg]` for vararg tuple
+ * so the index is `i + 1`. */
+ if (nargs < vararg) {
+ buf[i] = current_arg;
+ }
+ else {
+ buf[i + 1] = current_arg;
+ }
if (current_arg) {
--nkwargs;