Correct overflow check in PyTuple_New() (GH-14838)

This commit is contained in:
Sergey Fedoseev 2019-09-10 01:40:58 +05:00 committed by T. Wouters
parent 832e864008
commit 755d4ef824
1 changed files with 2 additions and 2 deletions

View File

@ -120,8 +120,8 @@ tuple_alloc(Py_ssize_t size)
#endif
{
/* Check for overflow */
if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - sizeof(PyTupleObject) -
sizeof(PyObject *)) / sizeof(PyObject *)) {
if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyTupleObject) -
sizeof(PyObject *))) / sizeof(PyObject *)) {
return (PyTupleObject *)PyErr_NoMemory();
}
op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);