Skip to content

Commit 35bf039

Browse files
picnixzseehwan80
authored andcommitted
pythongh-111178: fix UBSan failures in Modules/_winapi.c (pythonGH-129796)
Fix UBSan failures for `OverlappedObject` Suppress unused return values
1 parent b4f4de8 commit 35bf039

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Modules/_winapi.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,29 @@ typedef struct {
144144
Py_buffer write_buffer;
145145
} OverlappedObject;
146146

147+
#define OverlappedObject_CAST(op) ((OverlappedObject *)(op))
148+
147149
/*
148150
Note: tp_clear (overlapped_clear) is not implemented because it
149151
requires cancelling the IO operation if it's pending and the cancellation is
150152
quite complex and can fail (see: overlapped_dealloc).
151153
*/
152154
static int
153-
overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg)
155+
overlapped_traverse(PyObject *op, visitproc visit, void *arg)
154156
{
157+
OverlappedObject *self = OverlappedObject_CAST(op);
155158
Py_VISIT(self->read_buffer);
156159
Py_VISIT(self->write_buffer.obj);
157160
Py_VISIT(Py_TYPE(self));
158161
return 0;
159162
}
160163

161164
static void
162-
overlapped_dealloc(OverlappedObject *self)
165+
overlapped_dealloc(PyObject *op)
163166
{
164167
DWORD bytes;
165168
int err = GetLastError();
169+
OverlappedObject *self = OverlappedObject_CAST(op);
166170

167171
PyObject_GC_UnTrack(self);
168172
if (self->pending) {
@@ -3215,7 +3219,7 @@ winapi_clear(PyObject *module)
32153219
static void
32163220
winapi_free(void *module)
32173221
{
3218-
winapi_clear((PyObject *)module);
3222+
(void)winapi_clear((PyObject *)module);
32193223
}
32203224

32213225
static struct PyModuleDef winapi_module = {

0 commit comments

Comments
 (0)