diff options
author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2025-01-03 14:36:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-03 14:36:41 (GMT) |
commit | 1c9b0204796ddeaee710646871a4404b4cda1f1b (patch) | |
tree | 7a4afb6f1e2d9aafbd903a36f7d8a30dafc5c322 | |
parent | 56430320536a753236aadde59984c3c8f8777aa2 (diff) | |
download | cpython-1c9b0204796ddeaee710646871a4404b4cda1f1b.zip cpython-1c9b0204796ddeaee710646871a4404b4cda1f1b.tar.gz cpython-1c9b0204796ddeaee710646871a4404b4cda1f1b.tar.bz2 |
gh-111178: fix UBSan failures in `Modules/zlibmodule.c` (GH-128252)
-rw-r--r-- | Modules/zlibmodule.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 78dcce7..b90665a 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -221,6 +221,8 @@ typedef struct PyThread_type_lock lock; } compobject; +#define _compobject_CAST(op) ((compobject *)op) + static void zlib_error(zlibstate *state, z_stream zst, int err, const char *msg) { @@ -706,7 +708,7 @@ zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict) static void Dealloc(compobject *self) { - PyObject *type = (PyObject *)Py_TYPE(self); + PyTypeObject *type = Py_TYPE(self); PyThread_free_lock(self->lock); Py_XDECREF(self->unused_data); Py_XDECREF(self->unconsumed_tail); @@ -716,18 +718,20 @@ Dealloc(compobject *self) } static void -Comp_dealloc(compobject *self) +Comp_dealloc(PyObject *op) { + compobject *self = _compobject_CAST(op); if (self->is_initialised) - deflateEnd(&self->zst); + (void)deflateEnd(&self->zst); Dealloc(self); } static void -Decomp_dealloc(compobject *self) +Decomp_dealloc(PyObject *op) { + compobject *self = _compobject_CAST(op); if (self->is_initialised) - inflateEnd(&self->zst); + (void)inflateEnd(&self->zst); Dealloc(self); } |