mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
bail in unicode error's __str__ methods if the objects are not properly initialized (closes #21134)
This commit is contained in:
parent
24dfb05d4f
commit
9b09ba1234
3 changed files with 21 additions and 0 deletions
|
|
@ -1837,6 +1837,10 @@ UnicodeEncodeError_str(PyObject *self)
|
|||
PyObject *reason_str = NULL;
|
||||
PyObject *encoding_str = NULL;
|
||||
|
||||
if (!uself->object)
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
|
||||
/* Get reason and encoding as strings, which they might not be if
|
||||
they've been modified after we were contructed. */
|
||||
reason_str = PyObject_Str(uself->reason);
|
||||
|
|
@ -1955,6 +1959,10 @@ UnicodeDecodeError_str(PyObject *self)
|
|||
PyObject *reason_str = NULL;
|
||||
PyObject *encoding_str = NULL;
|
||||
|
||||
if (!uself->object)
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
|
||||
/* Get reason and encoding as strings, which they might not be if
|
||||
they've been modified after we were contructed. */
|
||||
reason_str = PyObject_Str(uself->reason);
|
||||
|
|
@ -2049,6 +2057,10 @@ UnicodeTranslateError_str(PyObject *self)
|
|||
PyObject *result = NULL;
|
||||
PyObject *reason_str = NULL;
|
||||
|
||||
if (!uself->object)
|
||||
/* Not properly initialized. */
|
||||
return PyUnicode_FromString("");
|
||||
|
||||
/* Get reason as a string, which it might not be if it's been
|
||||
modified after we were contructed. */
|
||||
reason_str = PyObject_Str(uself->reason);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue