Skip to content

Commit 2922429

Browse files
authored
gh-111178: fix UBSan failures in Modules/_randommodule.c (GH-129791)
Fix UBSan failures for `RandomObject` Suppress unused return values
1 parent 55f8bac commit 2922429

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Modules/_randommodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct {
117117
uint32_t state[N];
118118
} RandomObject;
119119

120+
#define RandomObject_CAST(op) ((RandomObject *)(op))
120121

121122
#include "clinic/_randommodule.c.h"
122123

@@ -551,7 +552,7 @@ _random_Random_getrandbits_impl(RandomObject *self, int k)
551552
}
552553

553554
static int
554-
random_init(RandomObject *self, PyObject *args, PyObject *kwds)
555+
random_init(PyObject *self, PyObject *args, PyObject *kwds)
555556
{
556557
PyObject *arg = NULL;
557558
_randomstate *state = _randomstate_type(Py_TYPE(self));
@@ -570,7 +571,7 @@ random_init(RandomObject *self, PyObject *args, PyObject *kwds)
570571
if (PyTuple_GET_SIZE(args) == 1)
571572
arg = PyTuple_GET_ITEM(args, 0);
572573

573-
return random_seed(self, arg);
574+
return random_seed(RandomObject_CAST(self), arg);
574575
}
575576

576577

@@ -665,7 +666,7 @@ _random_clear(PyObject *module)
665666
static void
666667
_random_free(void *module)
667668
{
668-
_random_clear((PyObject *)module);
669+
(void)_random_clear((PyObject *)module);
669670
}
670671

671672
static struct PyModuleDef _randommodule = {

0 commit comments

Comments
 (0)