8000 fix UBSan failures for `PySystemExitObject` · python/cpython@1886b07 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1886b07

Browse files
committed
fix UBSan failures for PySystemExitObject
1 parent 3f1196b commit 1886b07

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Objects/exceptions.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -691,14 +691,22 @@ SimpleExtendsException(PyExc_BaseException, GeneratorExit,
691691
* SystemExit extends BaseException
692692
*/
693693

694+
static inline PySystemExitObject *
695+
_PySystemExit_CAST(PyObject *self)
696+
{
697+
assert(PyObject_TypeCheck(self, (PyTypeObject *)PyExc_SystemExit));
698+
return (PySystemExitObject *)self;
699+
}
700+
694701
static int
695-
SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
702+
SystemExit_init(PyObject *op, PyObject *args, PyObject *kwds)
696703
{
697704
Py_ssize_t size = PyTuple_GET_SIZE(args);
698705

699-
if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
706+
if (BaseException_init(op, args, kwds) == -1)
700707
return -1;
701708

709+
PySystemExitObject *self = _PySystemExit_CAST(op);
702710
if (size == 0)
703711
return 0;
704712
if (size == 1) {
@@ -711,25 +719,27 @@ SystemExit_init(PySystemExitObject *self, PyObject *args, PyObject *kwds)
711719
}
712720

713721
static int
714-
SystemExit_clear(PySystemExitObject *self)
722+
SystemExit_clear(PyObject *op)
715723
{
724+
PySystemExitObject *self = _PySystemExit_CAST(op);
716725
Py_CLEAR(self->code);
717-
return BaseException_clear((PyBaseExceptionObject *)self);
726+
return BaseException_clear(op);
718727
}
719728

720729
static void
721-
SystemExit_dealloc(PySystemExitObject *self)
730+
SystemExit_dealloc(PyObject *self)
722731
{
723732
_PyObject_GC_UNTRACK(self);
724-
SystemExit_clear(self);
725-
Py_TYPE(self)->tp_free((PyObject *)self);
733+
(void)SystemExit_clear(self);
734+
Py_TYPE(self)->tp_free(self);
726735
}
727736

728737
static int
729-
SystemExit_traverse(PySystemExitObject *self, visitproc visit, void *arg)
738+
SystemExit_traverse(PyObject *op, visitproc visit, void *arg)
730739
{
740+
PySystemExitObject *self = _PySystemExit_CAST(op);
731741
Py_VISIT(self->code);
732-
return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
742+
return BaseException_traverse(op, visit, arg);
733743
}
734744

735745
static PyMemberDef SystemExit_members[] = {

0 commit comments

Comments
 (0)
0