Skip to content

Commit 50a70a0

Browse files
authored
GH-96678: Fix undefined behavior in ceval.c (#96708)
1 parent 72b29b2 commit 50a70a0

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
@@ -5532,7 +5532,13 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
55325532
/* Pack other positional arguments into the *args argument */
55335533
if (co->co_flags & CO_VARARGS) {
55345534
PyObject *u = NULL;
5535-
u = _PyTuple_FromArraySteal(args + n, argcount - n);
5535+
if (argcount == n) {
5536+
u = Py_NewRef(&_Py_SINGLETON(tuple_empty));
5537+
}
5538+
else {
5539+
assert(args != NULL);
5540+
u = _PyTuple_FromArraySteal(args + n, argcount - n);
5541+
}
55365542
if (u == NULL) {
55375543
goto fail_post_positional;
55385544
}

0 commit comments

Comments
 (0)