8000 gh-111178: fix UBSan failures in `Modules/_tkinter.c` by picnixz · Pull Request #129795 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-111178: fix UBSan failures in Modules/_tkinter.c #129795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 26, 2025
Prev Previous commit
Next Next commit
fix UBSan failures for TkttObject
  • Loading branch information
picnixz committed Jan 25, 2025
commit 8c0e55eac21a9384bab1eb817cbba8e19373ea12
12 changes: 9 additions & 3 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2689,13 +2689,19 @@ _tkinter_tkapp_deletefilehandler(TkappObject *self, PyObject *file)
/**** Tktt Object (timer token) ****/

static PyObject *Tktt_Type;
#define _TkttObject_Check(op) \
PyObject_TypeCheck((op), (PyTypeObject *)Tktt_Type)

typedef struct {
PyObject_HEAD
Tcl_TimerToken token;
PyObject *func;
} TkttObject;

#define _TkttObject_FAST_CAST(op) ((TkttObject *)(op))
#define _TkttObject_CAST(op) (assert(_TkttObject_Check(op)), \
_TkttObject_FAST_CAST(op))

/*[clinic input]
_tkinter.tktimertoken.deletetimerhandler

Expand Down Expand Up @@ -2740,7 +2746,7 @@ Tktt_New(PyObject *func)
static void
Tktt_Dealloc(PyObject *self)
{
TkttObject *v = (TkttObject *)self;
TkttObject *v = _TkttObject_CAST(self);
PyObject *func = v->func;
PyObject *tp = (PyObject *) Py_TYPE(self);

Expand All @@ -2753,7 +2759,7 @@ Tktt_Dealloc(PyObject *self)
static PyObject *
Tktt_Repr(PyObject *self)
{
TkttObject *v = (TkttObject *)self;
TkttObject *v = _TkttObject_CAST(self);
return PyUnicode_FromFormat("<tktimertoken at %p%s>",
v,
v->func == NULL ? ", handler deleted" : "");
Expand All @@ -2764,7 +2770,7 @@ Tktt_Repr(PyObject *self)
static void
TimerHandler(ClientData clientData)
{
TkttObject *v = (TkttObject *)clientData;
TkttObject *v = _TkttObject_CAST(clientData);
PyObject *func = v->func;
PyObject *res;

Expand Down
0