Skip to content

Commit 9889af8

Browse files
committed
fix UBSan failures for nldecoder_object
1 parent 0da5a81 commit 9889af8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Modules/_io/textio.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ struct nldecoder_object {
222222
unsigned int translate: 1;
223223
unsigned int seennl: 3;
224224
};
225+
#define _nldecoder_object_CAST(op) ((nldecoder_object *)(op))
225226

226227
/*[clinic input]
227228
_io.IncrementalNewlineDecoder.__init__
@@ -263,30 +264,32 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
263264
}
264265

265266
static int
266-
incrementalnewlinedecoder_traverse(nldecoder_object *self, visitproc visit,
267-
void *arg)
267+
incrementalnewlinedecoder_traverse(PyObject *op, visitproc visit, void *arg)
268268
{
269+
nldecoder_object *self = _nldecoder_object_CAST(op);
269270
Py_VISIT(Py_TYPE(self));
270271
Py_VISIT(self->decoder);
271272
Py_VISIT(self->errors);
272273
return 0;
273274
}
274275

275276
static int
276-
incrementalnewlinedecoder_clear(nldecoder_object *self)
277+
incrementalnewlinedecoder_clear(PyObject *op)
277278
{
279+
nldecoder_object *self = _nldecoder_object_CAST(op);
278280
Py_CLEAR(self->decoder);
279281
Py_CLEAR(self->errors);
280282
return 0;
281283
}
282284

283285
static void
284-
incrementalnewlinedecoder_dealloc(nldecoder_object *self)
286+
incrementalnewlinedecoder_dealloc(PyObject *op)
285287
{
288+
nldecoder_object *self = _nldecoder_object_CAST(op);
286289
PyTypeObject *tp = Py_TYPE(self);
287290
_PyObject_GC_UNTRACK(self);
288-
(void)incrementalnewlinedecoder_clear(self);
289-
tp->tp_free((PyObject *)self);
291+
(void)incrementalnewlinedecoder_clear(op);
292+
tp->tp_free(self);
290293
Py_DECREF(tp);
291294
}
292295

@@ -323,7 +326,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
323326
{
324327
PyObject *output;
325328
Py_ssize_t output_len;
326-
nldecoder_object *self = (nldecoder_object *) myself;
329+
nldecoder_object *self = _nldecoder_object_CAST(myself);
327330

328331
CHECK_INITIALIZED_DECODER(self);
329332

@@ -625,8 +628,9 @@ _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self)
625628
}
626629

627630
static PyObject *
628-
incrementalnewlinedecoder_newlines_get(nldecoder_object *self, void *context)
631+
incrementalnewlinedecoder_newlines_get(PyObject *op, void *Py_UNUSED(context))
629632
{
633+
nldecoder_object *self = _nldecoder_object_CAST(op);
630634
CHECK_INITIALIZED_DECODER(self);
631635

632636
switch (self->seennl) {
@@ -3313,7 +3317,7 @@ static PyMethodDef incrementalnewlinedecoder_methods[] = {
33133317
};
33143318

33153319
static PyGetSetDef incrementalnewlinedecoder_getset[] = {
3316-
{"newlines", (getter)incrementalnewlinedecoder_newlines_get, NULL, NULL},
3320+
{"newlines", incrementalnewlinedecoder_newlines_get, NULL, NULL},
33173321
{NULL}
33183322
};
33193323

0 commit comments

Comments
 (0)