diff options
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5cab149..407d770 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -689,7 +689,7 @@ _PySys_GetSizeOf(PyObject *o) { static PyObject *str__sizeof__ = NULL; PyObject *res = NULL; - size_t size; + Py_ssize_t size; /* Make sure the type is initialized. float gets initialized late */ if (PyType_Ready(Py_TYPE(o)) < 0) @@ -718,14 +718,19 @@ _PySys_GetSizeOf(PyObject *o) size = (size_t)PyInt_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 * |