mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
Issue #22193: Fixed integer overflow error in sys.getsizeof().
Fixed an error in _PySys_GetSizeOf declaration.
This commit is contained in:
parent
ed73010319
commit
030e92d1a5
3 changed files with 42 additions and 6 deletions
|
@ -868,7 +868,7 @@ _PySys_GetSizeOf(PyObject *o)
|
|||
{
|
||||
PyObject *res = NULL;
|
||||
PyObject *method;
|
||||
size_t size;
|
||||
Py_ssize_t size;
|
||||
|
||||
/* Make sure the type is initialized. float gets initialized late */
|
||||
if (PyType_Ready(Py_TYPE(o)) < 0)
|
||||
|
@ -889,15 +889,20 @@ _PySys_GetSizeOf(PyObject *o)
|
|||
if (res == NULL)
|
||||
return (size_t)-1;
|
||||
|
||||
size = PyLong_AsSize_t(res);
|
||||
size = PyLong_AsSsize_t(res);
|
||||
Py_DECREF(res);
|
||||
if (size == (size_t)-1 && PyErr_Occurred())
|
||||
if (size == -1 && PyErr_Occurred())
|
||||
return (size_t)-1;
|
||||
|
||||
if (size < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "__sizeof__() should return >= 0");
|
||||
return (size_t)-1;
|
||||
}
|
||||
|
||||
/* add gc_head size */
|
||||
if (PyObject_IS_GC(o))
|
||||
size += sizeof(PyGC_Head);
|
||||
return size;
|
||||
return ((size_t)size) + sizeof(PyGC_Head);
|
||||
return (size_t)size;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue