From 85dd6cb6df996b1197266d1a50ecc9187a91e481 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 30 Nov 2022 17:22:52 +0100 Subject: 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). --- Objects/bytearrayobject.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Objects/bytearrayobject.c') diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 0ba6fb5b76..f24690a02b 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2151,10 +2151,9 @@ static PyObject * bytearray_sizeof_impl(PyByteArrayObject *self) /*[clinic end generated code: output=738abdd17951c427 input=e27320fd98a4bc5a]*/ { - Py_ssize_t res; - - res = _PyObject_SIZE(Py_TYPE(self)) + self->ob_alloc * sizeof(char); - return PyLong_FromSsize_t(res); + size_t res = _PyObject_SIZE(Py_TYPE(self)); + res += (size_t)self->ob_alloc * sizeof(char); + return PyLong_FromSize_t(res); } static PySequenceMethods bytearray_as_sequence = { -- cgit v1.2.1