GH-96678: Fix undefined behavior in ceval.c (GH-96708)

(cherry picked from commit 50a70a083d)

Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
Miss Islington (bot) 2022-09-10 06:58:45 -07:00 committed by GitHub
parent c563b89261
commit 7033dc8adc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -6166,7 +6166,13 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
/* Pack other positional arguments into the *args argument */
if (co->co_flags & CO_VARARGS) {
PyObject *u = NULL;
u = _PyTuple_FromArraySteal(args + n, argcount - n);
if (argcount == n) {
u = Py_NewRef(&_Py_SINGLETON(tuple_empty));
}
else {
assert(args != NULL);
u = _PyTuple_FromArraySteal(args + n, argcount - n);
}
if (u == NULL) {
goto fail_post_positional;
}