diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-30 16:22:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-30 16:22:52 (GMT) |
commit | 85dd6cb6df996b1197266d1a50ecc9187a91e481 (patch) | |
tree | 774e93130f5e1b81dcd7a94982c189c718e84b91 /Modules/_decimal | |
parent | 18a6967544795cdcce45b45700b7a9ed3994b8fb (diff) | |
download | cpython-85dd6cb6df996b1197266d1a50ecc9187a91e481.zip cpython-85dd6cb6df996b1197266d1a50ecc9187a91e481.tar.gz cpython-85dd6cb6df996b1197266d1a50ecc9187a91e481.tar.bz2 |
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 'Modules/_decimal')
-rw-r--r-- | Modules/_decimal/_decimal.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 2d6e4e4..bc97615 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -4796,13 +4796,11 @@ dec_reduce(PyObject *self, PyObject *dummy UNUSED) static PyObject * dec_sizeof(PyObject *v, PyObject *dummy UNUSED) { - Py_ssize_t res; - - res = _PyObject_SIZE(Py_TYPE(v)); + size_t res = _PyObject_SIZE(Py_TYPE(v)); if (mpd_isdynamic_data(MPD(v))) { - res += MPD(v)->alloc * sizeof(mpd_uint_t); + res += (size_t)MPD(v)->alloc * sizeof(mpd_uint_t); } - return PyLong_FromSsize_t(res); + return PyLong_FromSize_t(res); } /* __trunc__ */ |