From f40658c2d04feeb3803cf0f3d34d915163b39b10 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 19 Oct 2022 16:52:02 +1300 Subject: [python] Avoid undefined behaviour Cast a parameter type explicitly rather than implicitly by casting the function pointer type, as the latter is undefined behaviour. Caught by ubsan. --- Lib/python/pyrun.swg | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'Lib/python/pyrun.swg') diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 9b6dd28ee..6b119be1c 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -240,7 +240,7 @@ typedef struct swig_varlinkobject { } swig_varlinkobject; SWIGINTERN PyObject * -swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { +swig_varlink_repr(PyObject *SWIGUNUSEDPARM(v)) { #if PY_VERSION_HEX >= 0x03000000 return PyUnicode_InternFromString(""); #else @@ -249,7 +249,8 @@ swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { } SWIGINTERN PyObject * -swig_varlink_str(swig_varlinkobject *v) { +swig_varlink_str(PyObject *o) { + swig_varlinkobject *v = (swig_varlinkobject *) o; #if PY_VERSION_HEX >= 0x03000000 PyObject *str = PyUnicode_InternFromString("("); PyObject *tail; @@ -287,7 +288,8 @@ swig_varlink_str(swig_varlinkobject *v) { } SWIGINTERN void -swig_varlink_dealloc(swig_varlinkobject *v) { +swig_varlink_dealloc(PyObject *o) { + swig_varlinkobject *v = (swig_varlinkobject *) o; swig_globalvar *var = v->vars; while (var) { swig_globalvar *n = var->next; @@ -298,7 +300,8 @@ swig_varlink_dealloc(swig_varlinkobject *v) { } SWIGINTERN PyObject * -swig_varlink_getattr(swig_varlinkobject *v, char *n) { +swig_varlink_getattr(PyObject *o, char *n) { + swig_varlinkobject *v = (swig_varlinkobject *) o; PyObject *res = NULL; swig_globalvar *var = v->vars; while (var) { @@ -315,7 +318,8 @@ swig_varlink_getattr(swig_varlinkobject *v, char *n) { } SWIGINTERN int -swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { +swig_varlink_setattr(PyObject *o, char *n, PyObject *p) { + swig_varlinkobject *v = (swig_varlinkobject *) o; int res = 1; swig_globalvar *var = v->vars; while (var) { -- cgit v1.2.1