Skip to content

Commit 3ff8de4

Browse files
committed
fix UBSan failures for pysqlite_Blob
1 parent 38c3cf6 commit 3ff8de4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Modules/_sqlite/blob.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,35 @@ close_blob(pysqlite_Blob *self)
2929
}
3030

3131
static int
32-
blob_traverse(pysqlite_Blob *self, visitproc visit, void *arg)
32+
blob_traverse(PyObject *op, visitproc visit, void *arg)
3333
{
34+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
3435
Py_VISIT(Py_TYPE(self));
3536
Py_VISIT(self->connection);
3637
return 0;
3738
}
3839

3940
static int
40-
blob_clear(pysqlite_Blob *self)
41+
blob_clear(PyObject *op)
4142
{
43+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
4244
Py_CLEAR(self->connection);
4345
return 0;
4446
}
4547

4648
static void
47-
blob_dealloc(pysqlite_Blob *self)
49+
blob_dealloc(PyObject *op)
4850
{
51+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
4952
PyTypeObject *tp = Py_TYPE(self);
5053
PyObject_GC_UnTrack(self);
5154

5255
close_blob(self);
5356

5457
if (self->in_weakreflist != NULL) {
55-
PyObject_ClearWeakRefs((PyObject*)self);
58+
PyObject_ClearWeakRefs(op);
5659
}
57-
tp->tp_clear((PyObject *)self);
60+
(void)tp->tp_clear(op);
5861
tp->tp_free(self);
5962
Py_DECREF(tp);
6063
}
@@ -373,8 +376,9 @@ blob_exit_impl(pysqlite_Blob *self, PyObject *type, PyObject *val,
373376
}
374377

375378
static Py_ssize_t
376-
blob_length(pysqlite_Blob *self)
379+
blob_length(PyObject *op)
377380
{
381+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
378382
if (!check_blob(self)) {
379383
return -1;
380384
}
@@ -449,8 +453,9 @@ subscript_slice(pysqlite_Blob *self, PyObject *item)
449453
}
450454

451455
static PyObject *
452-
blob_subscript(pysqlite_Blob *self, PyObject *item)
456+
blob_subscript(PyObject *op, PyObject *item)
453457
{
458+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
454459
if (!check_blob(self)) {
455460
return NULL;
456461
}
@@ -546,8 +551,9 @@ ass_subscript_slice(pysqlite_Blob *self, PyObject *item, PyObject *value)
546551
}
547552

548553
static int
549-
blob_ass_subscript(pysqlite_Blob *self, PyObject *item, PyObject *value)
554+
blob_ass_subscript(PyObject *op, PyObject *item, PyObject *value)
550555
{
556+
pysqlite_Blob *self = _pysqlite_Blob_CAST(op);
551557
if (!check_blob(self)) {
552558
return -1;
553559
}

Modules/_sqlite/blob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ typedef struct {
1818
PyObject *in_weakreflist;
1919
} pysqlite_Blob;
2020

21+
#define _pysqlite_Blob_CAST(op) ((pysqlite_Blob *)(op))
22+
2123
int pysqlite_blob_setup_types(PyObject *mod);
2224
void pysqlite_close_all_blobs(pysqlite_Connection *self);
2325

0 commit comments

Comments
 (0)