https://github.com/python/cpython/commit/29224295381d9c038339d25d98584cb146ba5f32
commit: 29224295381d9c038339d25d98584cb146ba5f32
branch: main
author: Bénédikt Tran <[email protected]>
committer: encukou <[email protected]>
date: 2025-02-21T14:59:04Z
summary:

gh-111178: fix UBSan failures in `Modules/_randommodule.c` (GH-129791)

Fix UBSan failures for `RandomObject`
Suppress unused return values

files:
M Modules/_randommodule.c

diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index ad66df47349db0..d5bac2f5b78120 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -117,6 +117,7 @@ typedef struct {
     uint32_t state[N];
 } RandomObject;
 
+#define RandomObject_CAST(op)   ((RandomObject *)(op))
 
 #include "clinic/_randommodule.c.h"
 
@@ -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));
@@ -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);
 }
 
 
@@ -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 = {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to