Skip to content

Commit 1c9b020

Browse files
authored
gh-111178: fix UBSan failures in Modules/zlibmodule.c (GH-128252)
1 parent 5643032 commit 1c9b020

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Modules/zlibmodule.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ typedef struct
221221
PyThread_type_lock lock;
222222
} compobject;
223223

224+
#define _compobject_CAST(op) ((compobject *)op)
225+
224226
static void
225227
zlib_error(zlibstate *state, z_stream zst, int err, const char *msg)
226228
{
@@ -706,7 +708,7 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict)
706708
static void
707709
Dealloc(compobject *self)
708710
{
709-
PyObject *type = (PyObject *)Py_TYPE(self);
711+
PyTypeObject *type = Py_TYPE(self);
710712
PyThread_free_lock(self->lock);
711713
Py_XDECREF(self->unused_data);
712714
Py_XDECREF(self->unconsumed_tail);
@@ -716,18 +718,20 @@ Dealloc(compobject *self)
716718
}
717719

718720
static void
719-
Comp_dealloc(compobject *self)
721+
Comp_dealloc(PyObject *op)
720722
{
723+
compobject *self = _compobject_CAST(op);
721724
if (self->is_initialised)
722-
deflateEnd(&self->zst);
725+
(void)deflateEnd(&self->zst);
723726
Dealloc(self);
724727
}
725728

726729
static void
727-
Decomp_dealloc(compobject *self)
730+
Decomp_dealloc(PyObject *op)
728731
{
732+
compobject *self = _compobject_CAST(op);
729733
if (self->is_initialised)
730-
inflateEnd(&self->zst);
734+
(void)inflateEnd(&self->zst);
731735
Dealloc(self);
732736
}
733737

0 commit comments

Comments
 (0)