summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-20 13:38:22 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-20 13:38:22 (GMT)
commitdd4d1c4f5d1b5c91ed2fb1a9209ee3434bc20a2b (patch)
treef2fa55a70115e18f1f96e88a0fe1c3011dff7b40 /Objects/object.c
parentaefd766eedad6d0315ef16c276ab7f30a5b3d690 (diff)
downloadcpython-dd4d1c4f5d1b5c91ed2fb1a9209ee3434bc20a2b.zip
cpython-dd4d1c4f5d1b5c91ed2fb1a9209ee3434bc20a2b.tar.gz
cpython-dd4d1c4f5d1b5c91ed2fb1a9209ee3434bc20a2b.tar.bz2
_PyObject_GetDictPtr(): when the offset is negative, always align --
we can't trust that tp_basicsize is aligned. Fixes SF bug #462848.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 668bd4f..6d7a5e9 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1150,18 +1150,13 @@ _PyObject_GetDictPtr(PyObject *obj)
return NULL;
if (dictoffset < 0) {
dictoffset += tp->tp_basicsize;
+ dictoffset += tp->tp_itemsize * ((PyVarObject *)obj)->ob_size;
assert(dictoffset > 0); /* Sanity check */
- if (tp->tp_itemsize > 0) {
- int n = ((PyVarObject *)obj)->ob_size;
- if (n > 0) {
- dictoffset += tp->tp_itemsize * n;
- /* Round up, if necessary */
- if (tp->tp_itemsize % PTRSIZE != 0) {
- dictoffset += PTRSIZE - 1;
- dictoffset /= PTRSIZE;
- dictoffset *= PTRSIZE;
- }
- }
+ /* Round up, if necessary */
+ if (dictoffset % PTRSIZE != 0) {
+ dictoffset /= PTRSIZE;
+ dictoffset += 1;
+ dictoffset *= PTRSIZE;
}
}
return (PyObject **) ((char *)obj + dictoffset);