]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-99845: _PyObject_DictPointer(): fix dictoffset cast (#99922)
authorVictor Stinner <vstinner@python.org>
Thu, 1 Dec 2022 13:07:58 +0000 (14:07 +0100)
committerGitHub <noreply@github.com>
Thu, 1 Dec 2022 13:07:58 +0000 (14:07 +0100)
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.

Objects/object.c

index 6a22f27de0b1c892b7385187ad6d04ce34958ddd..c4f2786c50a02b1b73369e94afa84a8d8a96ec77 100644 (file)
@@ -1076,8 +1076,9 @@ _PyObject_DictPointer(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);
     }