Skip to content
Next Next commit
fix UBSan failures for Pdata
  • Loading branch information
picnixz committed Jan 25, 2025
commit 47cddff3315d899828778ffcb1dc1b479265865e
9 changes: 6 additions & 3 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,24 +410,27 @@ typedef struct {
Py_ssize_t allocated; /* number of slots in data allocated */
} Pdata;

#define _Pdata_CAST(op) ((Pdata *)(op))

static int
Pdata_traverse(Pdata *self, visitproc visit, void *arg)
Pdata_traverse(PyObject *self, visitproc visit, void *arg)
{
Py_VISIT(Py_TYPE(self));
return 0;
}

static void
Pdata_dealloc(Pdata *self)
Pdata_dealloc(PyObject *op)
{
Pdata *self = _Pdata_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
PyObject_GC_UnTrack(self);
Py_ssize_t i = Py_SIZE(self);
while (--i >= 0) {
Py_DECREF(self->data[i]);
}
PyMem_Free(self->data);
tp->tp_free((PyObject *)self);
tp->tp_free(self);
Py_DECREF(tp);
}

Expand Down