Skip to content

Commit 88e249b

Browse files
committed
Fix int __sizeof__ to use a minimum absolute ob_size of 1
Fixes behavior where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for empty ints.
1 parent e83f88a commit 88e249b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Objects/longobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5879,7 +5879,7 @@ int___sizeof___impl(PyObject *self)
58795879
{
58805880
Py_ssize_t res;
58815881

5882-
res = offsetof(PyLongObject, ob_digit) + Py_ABS(Py_SIZE(self))*sizeof(digit);
5882+
res = offsetof(PyLongObject, ob_digit) + Py_MAX(Py_ABS(Py_SIZE(self)), 1)*sizeof(digit);
58835883
return res;
58845884
}
58855885

0 commit comments

Comments
 (0)