Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix UBSan failures for nldecoder_object
  • Loading branch information
picnixz committed Jan 20, 2025
commit 9889af87da581969bd081e5cf265346eb33256b7
22 changes: 13 additions & 9 deletions Modules/_io/textio.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ struct nldecoder_object {
unsigned int translate: 1;
unsigned int seennl: 3;
};
#define _nldecoder_object_CAST(op) ((nldecoder_object *)(op))

/*[clinic input]
_io.IncrementalNewlineDecoder.__init__
Expand Down Expand Up @@ -263,30 +264,32 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
}

static int
incrementalnewlinedecoder_traverse(nldecoder_object *self, visitproc visit,
void *arg)
incrementalnewlinedecoder_traverse(PyObject *op, visitproc visit, void *arg)
{
nldecoder_object *self = _nldecoder_object_CAST(op);
Py_VISIT(Py_TYPE(self));
Py_VISIT(self->decoder);
Py_VISIT(self->errors);
return 0;
}

static int
incrementalnewlinedecoder_clear(nldecoder_object *self)
incrementalnewlinedecoder_clear(PyObject *op)
{
nldecoder_object *self = _nldecoder_object_CAST(op);
Py_CLEAR(self->decoder);
Py_CLEAR(self->errors);
return 0;
}

static void
incrementalnewlinedecoder_dealloc(nldecoder_object *self)
incrementalnewlinedecoder_dealloc(PyObject *op)
{
nldecoder_object *self = _nldecoder_object_CAST(op);
PyTypeObject *tp = Py_TYPE(self);
_PyObject_GC_UNTRACK(self);
(void)incrementalnewlinedecoder_clear(self);
tp->tp_free((PyObject *)self);
(void)incrementalnewlinedecoder_clear(op);
tp->tp_free(self);
Py_DECREF(tp);
}

Expand Down Expand Up @@ -323,7 +326,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
{
PyObject *output;
Py_ssize_t output_len;
nldecoder_object *self = (nldecoder_object *) myself;
nldecoder_object *self = _nldecoder_object_CAST(myself);

CHECK_INITIALIZED_DECODER(self);

Expand Down Expand Up @@ -625,8 +628,9 @@ _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self)
}

static PyObject *
incrementalnewlinedecoder_newlines_get(nldecoder_object *self, void *context)
incrementalnewlinedecoder_newlines_get(PyObject *op, void *Py_UNUSED(context))
{
nldecoder_object *self = _nldecoder_object_CAST(op);
CHECK_INITIALIZED_DECODER(self);

switch (self->seennl) {
Expand Down Expand Up @@ -3313,7 +3317,7 @@ static PyMethodDef incrementalnewlinedecoder_methods[] = {
};

static PyGetSetDef incrementalnewlinedecoder_getset[] = {
{"newlines", (getter)incrementalnewlinedecoder_newlines_get, NULL, NULL},
{"newlines", incrementalnewlinedecoder_newlines_get, NULL, NULL},
{NULL}
};

Expand Down