From: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Date: Mon, 24 Feb 2025 13:06:13 +0000 (+0100) Subject: gh-111178: fix UBSan failures in `Modules/_winapi.c` (GH-129796) X-Git-Tag: v3.14.0a6~291 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=805839021ba7074423811ba07995ae57984a46d3;p=thirdparty%2FPython%2Fcpython.git gh-111178: fix UBSan failures in `Modules/_winapi.c` (GH-129796) Fix UBSan failures for `OverlappedObject` Suppress unused return values --- diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 786a828f0090..4391bfc09f9c 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -144,14 +144,17 @@ typedef struct { Py_buffer write_buffer; } OverlappedObject; +#define OverlappedObject_CAST(op) ((OverlappedObject *)(op)) + /* Note: tp_clear (overlapped_clear) is not implemented because it requires cancelling the IO operation if it's pending and the cancellation is quite complex and can fail (see: overlapped_dealloc). */ static int -overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg) +overlapped_traverse(PyObject *op, visitproc visit, void *arg) { + OverlappedObject *self = OverlappedObject_CAST(op); Py_VISIT(self->read_buffer); Py_VISIT(self->write_buffer.obj); Py_VISIT(Py_TYPE(self)); @@ -159,10 +162,11 @@ overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg) } static void -overlapped_dealloc(OverlappedObject *self) +overlapped_dealloc(PyObject *op) { DWORD bytes; int err = GetLastError(); + OverlappedObject *self = OverlappedObject_CAST(op); PyObject_GC_UnTrack(self); if (self->pending) { @@ -3215,7 +3219,7 @@ winapi_clear(PyObject *module) static void winapi_free(void *module) { - winapi_clear((PyObject *)module); + (void)winapi_clear((PyObject *)module); } static struct PyModuleDef winapi_module = {