diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-30 14:48:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-05-30 14:48:19 (GMT) |
commit | ac5569b1fa483c50edca82bab1ab0a8a927ba86a (patch) | |
tree | 9eada65cbf98a2158fda4b3a668ad5ee5969f1c5 /Objects/bytesobject.c | |
parent | bf2b3b72d370f866aa5b8f9077ff37e7c53de894 (diff) | |
parent | fa494fd88384acc52cf9292d0c89e2961c8f747f (diff) | |
download | cpython-ac5569b1fa483c50edca82bab1ab0a8a927ba86a.zip cpython-ac5569b1fa483c50edca82bab1ab0a8a927ba86a.tar.gz cpython-ac5569b1fa483c50edca82bab1ab0a8a927ba86a.tar.bz2 |
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r-- | Objects/bytesobject.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index c576678..6a6e930 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -1419,25 +1419,36 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op) Py_ssize_t len_a, len_b; Py_ssize_t min_len; PyObject *result; + int rc; /* Make sure both arguments are strings. */ if (!(PyBytes_Check(a) && PyBytes_Check(b))) { if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) { - if (PyObject_IsInstance((PyObject*)a, - (PyObject*)&PyUnicode_Type) || - PyObject_IsInstance((PyObject*)b, - (PyObject*)&PyUnicode_Type)) { + rc = PyObject_IsInstance((PyObject*)a, + (PyObject*)&PyUnicode_Type); + if (!rc) + rc = PyObject_IsInstance((PyObject*)b, + (PyObject*)&PyUnicode_Type); + if (rc < 0) + return NULL; + if (rc) { if (PyErr_WarnEx(PyExc_BytesWarning, - "Comparison between bytes and string", 1)) + "Comparison between bytes and string", 1)) return NULL; } - else if (PyObject_IsInstance((PyObject*)a, - (PyObject*)&PyLong_Type) || - PyObject_IsInstance((PyObject*)b, - (PyObject*)&PyLong_Type)) { - if (PyErr_WarnEx(PyExc_BytesWarning, - "Comparison between bytes and int", 1)) + else { + rc = PyObject_IsInstance((PyObject*)a, + (PyObject*)&PyLong_Type); + if (!rc) + rc = PyObject_IsInstance((PyObject*)b, + (PyObject*)&PyLong_Type); + if (rc < 0) return NULL; + if (rc) { + if (PyErr_WarnEx(PyExc_BytesWarning, + "Comparison between bytes and int", 1)) + return NULL; + } } } result = Py_NotImplemented; |