Skip to content

Commit

Permalink
gh-99845: _PyObject_DictPointer(): fix dictoffset cast (GH-99922)
Browse files Browse the repository at this point in the history
Cast size_t to Py_ssize_t, rather than casting it to long. On 64-bit
Windows, long is 32-bit whereas Py_ssize_t is 64-bit.
(cherry picked from commit 9707bf2)

Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
miss-islington and vstinner authored Dec 1, 2022
1 parent 807b103 commit 64dae2e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,9 @@ _PyObject_GetDictPtr(PyObject *obj)
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);
}
Expand Down

0 comments on commit 64dae2e

Please sign in to comment.