8000 fix UBSan failures for `KeyError` · python/cpython@150f34e · GitHub
[go: up one dir, main page]

Skip to content

Commit 150f34e

Browse files
committed
fix UBSan failures for KeyError
1 parent 2640a34 commit 150f34e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Objects/exceptions.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,8 +2719,9 @@ SimpleExtendsException(PyExc_LookupError, IndexError,
27192719
/*
27202720
* KeyError extends LookupError
27212721
*/
2722+
27222723
static PyObject *
2723-
KeyError_str(PyBaseExceptionObject *self)
2724+
KeyError_str(PyObject *op)
27242725
{
27252726
/* If args is a tuple of exactly one item, apply repr to args[0].
27262727
This is done so that e.g. the exception raised by {}[''] prints
@@ -2731,10 +2732,11 @@ KeyError_str(PyBaseExceptionObject *self)
27312732
string, that string will be displayed in quotes. Too bad.
27322733
If args is anything else, use the default BaseException__str__().
27332734
*/
2735+
PyBaseExceptionObject *self = _PyBaseExceptionObject_CAST(op);
27342736
if (PyTuple_GET_SIZE(self->args) == 1) {
27352737
return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0));
27362738
}
2737-
return BaseException_str(self);
2739+
return BaseException_str(op);
27382740
}
27392741

27402742
ComplexExtendsException(PyExc_LookupError, KeyError, BaseException,

0 commit comments

Comments
 (0)
0