Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index ca66a45..c4ba715 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -194,8 +194,11 @@
}
/* if (lo >= hi), return length of 0. */
- if (PyObject_RichCompareBool(lo, hi, Py_GE) == 1) {
+ cmp_result = PyObject_RichCompareBool(lo, hi, Py_GE);
+ if (cmp_result != 0) {
Py_XDECREF(step);
+ if (cmp_result < 0)
+ return NULL;
return PyLong_FromLong(0);
}