Kaydet (Commit) dd4d1c4f authored tarafından Guido van Rossum's avatar Guido van Rossum

_PyObject_GetDictPtr(): when the offset is negative, always align --

we can't trust that tp_basicsize is aligned.  Fixes SF bug #462848.
üst aefd766e
...@@ -1150,20 +1150,15 @@ _PyObject_GetDictPtr(PyObject *obj) ...@@ -1150,20 +1150,15 @@ _PyObject_GetDictPtr(PyObject *obj)
return NULL; return NULL;
if (dictoffset < 0) { if (dictoffset < 0) {
dictoffset += tp->tp_basicsize; dictoffset += tp->tp_basicsize;
dictoffset += tp->tp_itemsize * ((PyVarObject *)obj)->ob_size;
assert(dictoffset > 0); /* Sanity check */ 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 */ /* Round up, if necessary */
if (tp->tp_itemsize % PTRSIZE != 0) { if (dictoffset % PTRSIZE != 0) {
dictoffset += PTRSIZE - 1;
dictoffset /= PTRSIZE; dictoffset /= PTRSIZE;
dictoffset += 1;
dictoffset *= PTRSIZE; dictoffset *= PTRSIZE;
} }
} }
}
}
return (PyObject **) ((char *)obj + dictoffset); return (PyObject **) ((char *)obj + dictoffset);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment