diff options
author | Guido van Rossum <guido@python.org> | 1998-07-21 21:56:41 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-07-21 21:56:41 (GMT) |
commit | b4db1944c4392cb1510f01dcd2b10da6949b83fc (patch) | |
tree | fe7b9eb74151e6affa0cb6f7c897717c9b7fadb7 | |
parent | 052969a6022a06414b11ab6fe294d5af01d20a59 (diff) | |
download | cpython-b4db1944c4392cb1510f01dcd2b10da6949b83fc.zip cpython-b4db1944c4392cb1510f01dcd2b10da6949b83fc.tar.gz cpython-b4db1944c4392cb1510f01dcd2b10da6949b83fc.tar.bz2 |
When comparing objects, always check that tp_compare is not NULL
before calling it. This check was there when the objects were of the
same type *before* coercion, but not if they initially differed but
became the same *after* coercion.
-rw-r--r-- | Objects/object.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c index 2428cc9..b62477a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -312,14 +312,18 @@ PyObject_Compare(v, w) if ((vtp = v->ob_type) != (wtp = w->ob_type)) { char *vname = vtp->tp_name; char *wname = wtp->tp_name; - if (vtp->tp_as_number != NULL && - wtp->tp_as_number != NULL) { + if (vtp->tp_as_number != NULL && wtp->tp_as_number != NULL) { int err; err = PyNumber_CoerceEx(&v, &w); if (err < 0) return -1; else if (err == 0) { - int cmp = (*v->ob_type->tp_compare)(v, w); + int cmp; + vtp = v->ob_type; + if (vtp->tp_compare == NULL) + cmp = (v < w) ? -1 : 1; + else + cmp = (*vtp->tp_compare)(v, w); Py_DECREF(v); Py_DECREF(w); return cmp; |