summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-08 09:58:51 +0300
committerGitHub <noreply@github.com>2017-09-08 09:58:51 +0300
commite3b2b4b8d9e751b49e3550cb83ba39b54fdc377c (patch)
treee3cf5fd257df7ac82e2bd47811720daf22ce0666 /Objects/unicodeobject.c
parentShow example of itemgetter() applied to a dictionary (#3431) (diff)
downloadcpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.tar.gz
cpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.tar.bz2
cpython-e3b2b4b8d9e751b49e3550cb83ba39b54fdc377c.zip
bpo-31393: Fix the use of PyUnicode_READY(). (#3451)
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index db1516ddf65..c4d93fca045 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4185,10 +4185,13 @@ PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index)
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 @@ unicode_getitem(PyObject *self, Py_ssize_t index)
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;