Skip to content

Commit

Permalink
gh-111178: fix UBSan failures in Modules/_randommodule.c (GH-129791)
Browse files Browse the repository at this point in the history
Fix UBSan failures for `RandomObject`
Suppress unused return values
  • Loading branch information
picnixz authored Feb 21, 2025
1 parent 55f8bac commit 2922429
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Modules/_randommodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ typedef struct {
uint32_t state[N];
} RandomObject;

#define RandomObject_CAST(op) ((RandomObject *)(op))

#include "clinic/_randommodule.c.h"

Expand Down Expand Up @@ -551,7 +552,7 @@ _random_Random_getrandbits_impl(RandomObject *self, int k)
}

static int
random_init(RandomObject *self, PyObject *args, PyObject *kwds)
random_init(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *arg = NULL;
_randomstate *state = _randomstate_type(Py_TYPE(self));
Expand All @@ -570,7 +571,7 @@ random_init(RandomObject *self, PyObject *args, PyObject *kwds)
if (PyTuple_GET_SIZE(args) == 1)
arg = PyTuple_GET_ITEM(args, 0);

return random_seed(self, arg);
return random_seed(RandomObject_CAST(self), arg);
}


Expand Down Expand Up @@ -665,7 +666,7 @@ _random_clear(PyObject *module)
static void
_random_free(void *module)
{
_random_clear((PyObject *)module);
(void)_random_clear((PyObject *)module);
}

static struct PyModuleDef _randommodule = {
Expand Down

0 comments on commit 2922429

Please sign in to comment.