bpo-31393: Fix the use of PyUnicode_READY(). (#3451)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index db1516d..c4d93fc 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4185,10 +4185,13 @@
void *data;
int kind;
- if (!PyUnicode_Check(unicode) || PyUnicode_READY(unicode) == -1) {
+ if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return (Py_UCS4)-1;
}
+ if (PyUnicode_READY(unicode) == -1) {
+ return (Py_UCS4)-1;
+ }
if (index < 0 || index >= PyUnicode_GET_LENGTH(unicode)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return (Py_UCS4)-1;
@@ -11668,10 +11671,13 @@
enum PyUnicode_Kind kind;
Py_UCS4 ch;
- if (!PyUnicode_Check(self) || PyUnicode_READY(self) == -1) {
+ if (!PyUnicode_Check(self)) {
PyErr_BadArgument();
return NULL;
}
+ if (PyUnicode_READY(self) == -1) {
+ return NULL;
+ }
if (index < 0 || index >= PyUnicode_GET_LENGTH(self)) {
PyErr_SetString(PyExc_IndexError, "string index out of range");
return NULL;