diff options
| author | Victor Stinner <vstinner@python.org> | 2022-11-30 17:22:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-30 17:22:52 +0100 |
| commit | 85dd6cb6df996b1197266d1a50ecc9187a91e481 (patch) | |
| tree | 774e93130f5e1b81dcd7a94982c189c718e84b91 /Objects/setobject.c | |
| parent | 18a6967544795cdcce45b45700b7a9ed3994b8fb (diff) | |
| download | cpython-git-85dd6cb6df996b1197266d1a50ecc9187a91e481.tar.gz | |
gh-99845: Use size_t type in __sizeof__() methods (#99846)
The implementation of __sizeof__() methods using _PyObject_SIZE() now
use an unsigned type (size_t) to compute the size, rather than a signed
type (Py_ssize_t).
Cast explicitly signed (Py_ssize_t) values to unsigned type
(Py_ssize_t).
Diffstat (limited to 'Objects/setobject.c')
| -rw-r--r-- | Objects/setobject.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index ae9e9b9944..fcdda2a0bc 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1957,12 +1957,11 @@ done: static PyObject * set_sizeof(PySetObject *so, PyObject *Py_UNUSED(ignored)) { - Py_ssize_t res; - - res = _PyObject_SIZE(Py_TYPE(so)); - if (so->table != so->smalltable) - res = res + (so->mask + 1) * sizeof(setentry); - return PyLong_FromSsize_t(res); + size_t res = _PyObject_SIZE(Py_TYPE(so)); + if (so->table != so->smalltable) { + res += ((size_t)so->mask + 1) * sizeof(setentry); + } + return PyLong_FromSize_t(res); } PyDoc_STRVAR(sizeof_doc, "S.__sizeof__() -> size of S in memory, in bytes"); |
