Skip to content

Commit 7033dc8

Browse files
GH-96678: Fix undefined behavior in ceval.c (GH-96708)
(cherry picked from commit 50a70a0) Co-authored-by: Mark Shannon <[email protected]>
1 parent c563b89 commit 7033dc8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix case of undefined behavior in ceval.c

Python/ceval.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -6166,7 +6166,13 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
61666166
/* Pack other positional arguments into the *args argument */
61676167
if (co->co_flags & CO_VARARGS) {
61686168
PyObject *u = NULL;
6169-
u = _PyTuple_FromArraySteal(args + n, argcount - n);
6169+
if (argcount == n) {
6170+
u = Py_NewRef(&_Py_SINGLETON(tuple_empty));
6171+
}
6172+
else {
6173+
assert(args != NULL);
6174+
u = _PyTuple_FromArraySteal(args + n, argcount - n);
6175+
}
61706176
if (u == NULL) {
61716177
goto fail_post_positional;
61726178
}

0 commit comments

Comments
 (0)