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).
This commit is contained in:
@@ -2090,13 +2090,11 @@ PyDoc_STRVAR(s_sizeof__doc__,
|
||||
static PyObject *
|
||||
s_sizeof(PyStructObject *self, void *unused)
|
||||
{
|
||||
Py_ssize_t size;
|
||||
formatcode *code;
|
||||
|
||||
size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode);
|
||||
for (code = self->s_codes; code->fmtdef != NULL; code++)
|
||||
size_t size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode);
|
||||
for (formatcode *code = self->s_codes; code->fmtdef != NULL; code++) {
|
||||
size += sizeof(formatcode);
|
||||
return PyLong_FromSsize_t(size);
|
||||
}
|
||||
return PyLong_FromSize_t(size);
|
||||
}
|
||||
|
||||
/* List of functions */
|
||||
|
||||
Reference in New Issue
Block a user