summaryrefslogtreecommitdiff
path: root/Objects/object.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-11-29 12:15:21 +0100
committerGitHub <noreply@github.com>2022-11-29 12:15:21 +0100
commit74d5f61ebd1cb14907bf7dae1ad9c1e676707bc5 (patch)
tree2ff77f8a0571edb5690e9e22209fb76e99a81560 /Objects/object.c
parent4246fe977d850f8b78505c982f055d33d52ff339 (diff)
downloadcpython-git-74d5f61ebd1cb14907bf7dae1ad9c1e676707bc5.tar.gz
gh-99845: Clean up _PyObject_VAR_SIZE() usage (#99847)
* code_sizeof() now uses an unsigned type (size_t) to compute the result. * Fix _PyObject_ComputedDictPointer(): cast _PyObject_VAR_SIZE() to Py_ssize_t, rather than long: it's a different type on 64-bit Windows. * Clarify that _PyObject_VAR_SIZE() uses an unsigned type (size_t).
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c
index a499cb32b2..687bd36d2b 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1043,22 +1043,25 @@ PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value)
PyObject **
_PyObject_ComputedDictPointer(PyObject *obj)
{
- Py_ssize_t dictoffset;
PyTypeObject *tp = Py_TYPE(obj);
-
assert((tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
- dictoffset = tp->tp_dictoffset;
- if (dictoffset == 0)
+
+ Py_ssize_t dictoffset = tp->tp_dictoffset;
+ if (dictoffset == 0) {
return NULL;
+ }
+
if (dictoffset < 0) {
assert(dictoffset != -1);
+
Py_ssize_t tsize = Py_SIZE(obj);
if (tsize < 0) {
tsize = -tsize;
}
size_t size = _PyObject_VAR_SIZE(tp, tsize);
+ assert(size <= (size_t)PY_SSIZE_T_MAX);
+ dictoffset += (Py_ssize_t)size;
- dictoffset += (long)size;
_PyObject_ASSERT(obj, dictoffset > 0);
_PyObject_ASSERT(obj, dictoffset % SIZEOF_VOID_P == 0);
}