Skip to content

Commit 82e541b

Browse files
authored
gh-111178: fix UBSan failures for Modules/_testbuffer.c (#131612)
1 parent ef06508 commit 82e541b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Modules/_testbuffer.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,9 @@ ptr_from_index(Py_buffer *base, Py_ssize_t index)
15861586
}
15871587

15881588
static PyObject *
1589-
ndarray_item(NDArrayObject *self, Py_ssize_t index)
1589+
ndarray_item(PyObject *op, Py_ssize_t index)
15901590
{
1591+
NDArrayObject *self = (NDArrayObject *)op;
15911592
ndbuf_t *ndbuf = self->head;
15921593
Py_buffer *base = &ndbuf->base;
15931594
char *ptr;
@@ -1801,7 +1802,7 @@ ndarray_subscript(PyObject *op, PyObject *key)
18011802
Py_ssize_t index = PyLong_AsSsize_t(key);
18021803
if (index == -1 && PyErr_Occurred())
18031804
return NULL;
1804-
return ndarray_item(self, index);
1805+
return ndarray_item(op, index);
18051806
}
18061807

18071808
nd = (NDArrayObject *)ndarray_new(&NDArray_Type, NULL, NULL);
@@ -1966,10 +1967,10 @@ static PyMappingMethods ndarray_as_mapping = {
19661967
};
19671968

19681969
static PySequenceMethods ndarray_as_sequence = {
1969-
0, /* sq_length */
1970-
0, /* sq_concat */
1971-
0, /* sq_repeat */
1972-
(ssizeargfunc)ndarray_item, /* sq_item */
1970+
0, /* sq_length */
1971+
0, /* sq_concat */
1972+
0, /* sq_repeat */
1973+
ndarray_item, /* sq_item */
19731974
};
19741975

19751976

@@ -2742,16 +2743,17 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds)
27422743
}
27432744

27442745
static void
2745-
staticarray_dealloc(StaticArrayObject *self)
2746+
staticarray_dealloc(PyObject *self)
27462747
{
27472748
PyObject_Free(self);
27482749
}
27492750

27502751
/* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked,
27512752
which makes this object a non-compliant exporter! */
27522753
static int
2753-
staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
2754+
staticarray_getbuf(PyObject *op, Py_buffer *view, int flags)
27542755
{
2756+
StaticArrayObject *self = (StaticArrayObject *)op;
27552757
*view = static_buffer;
27562758

27572759
if (self->legacy_mode) {
@@ -2765,7 +2767,7 @@ staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
27652767
}
27662768

27672769
static PyBufferProcs staticarray_as_buffer = {
2768-
(getbufferproc)staticarray_getbuf, /* bf_getbuffer */
2770+
staticarray_getbuf, /* bf_getbuffer */
27692771
NULL, /* bf_releasebuffer */
27702772
};
27712773

@@ -2774,7 +2776,7 @@ static PyTypeObject StaticArray_Type = {
27742776
"staticarray", /* Name of this type */
27752777
sizeof(StaticArrayObject), /* Basic object size */
27762778
0, /* Item size for varobject */
2777-
(destructor)staticarray_dealloc, /* tp_dealloc */
2779+
staticarray_dealloc, /* tp_dealloc */
27782780
0, /* tp_vectorcall_offset */
27792781
0, /* tp_getattr */
27802782
0, /* tp_setattr */

0 commit comments

Comments
 (0)