https://github.com/python/cpython/commit/82e541bf910fcbfbfc05ae998298fb23a0e1bbbc commit: 82e541bf910fcbfbfc05ae998298fb23a0e1bbbc branch: main author: Bénédikt Tran <10796600+picn...@users.noreply.github.com> committer: picnixz <10796600+picn...@users.noreply.github.com> date: 2025-03-24T10:46:25+01:00 summary:
gh-111178: fix UBSan failures for `Modules/_testbuffer.c` (#131612) files: M Modules/_testbuffer.c diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index 7ecb11da2bb6af..7fc4d61db29469 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -1586,8 +1586,9 @@ ptr_from_index(Py_buffer *base, Py_ssize_t index) } static PyObject * -ndarray_item(NDArrayObject *self, Py_ssize_t index) +ndarray_item(PyObject *op, Py_ssize_t index) { + NDArrayObject *self = (NDArrayObject *)op; ndbuf_t *ndbuf = self->head; Py_buffer *base = &ndbuf->base; char *ptr; @@ -1801,7 +1802,7 @@ ndarray_subscript(PyObject *op, PyObject *key) Py_ssize_t index = PyLong_AsSsize_t(key); if (index == -1 && PyErr_Occurred()) return NULL; - return ndarray_item(self, index); + return ndarray_item(op, index); } nd = (NDArrayObject *)ndarray_new(&NDArray_Type, NULL, NULL); @@ -1966,10 +1967,10 @@ static PyMappingMethods ndarray_as_mapping = { }; static PySequenceMethods ndarray_as_sequence = { - 0, /* sq_length */ - 0, /* sq_concat */ - 0, /* sq_repeat */ - (ssizeargfunc)ndarray_item, /* sq_item */ + 0, /* sq_length */ + 0, /* sq_concat */ + 0, /* sq_repeat */ + ndarray_item, /* sq_item */ }; @@ -2742,7 +2743,7 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds) } static void -staticarray_dealloc(StaticArrayObject *self) +staticarray_dealloc(PyObject *self) { PyObject_Free(self); } @@ -2750,8 +2751,9 @@ staticarray_dealloc(StaticArrayObject *self) /* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked, which makes this object a non-compliant exporter! */ static int -staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags) +staticarray_getbuf(PyObject *op, Py_buffer *view, int flags) { + StaticArrayObject *self = (StaticArrayObject *)op; *view = static_buffer; if (self->legacy_mode) { @@ -2765,7 +2767,7 @@ staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags) } static PyBufferProcs staticarray_as_buffer = { - (getbufferproc)staticarray_getbuf, /* bf_getbuffer */ + staticarray_getbuf, /* bf_getbuffer */ NULL, /* bf_releasebuffer */ }; @@ -2774,7 +2776,7 @@ static PyTypeObject StaticArray_Type = { "staticarray", /* Name of this type */ sizeof(StaticArrayObject), /* Basic object size */ 0, /* Item size for varobject */ - (destructor)staticarray_dealloc, /* tp_dealloc */ + staticarray_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */ 0, /* tp_getattr */ 0, /* tp_setattr */ _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com