Commits

Andrew Kuchling committed eda931f

[Backport r42951 | guido.van.rossum]

Fix three nits found by Coverity, adding null checks and comments.

[This commit only makes two changes. One change in the original patch
is just adding a comment, and another adds a 'base != NULL' check to
silence Coverity, but a comment adds that that base is never going to
be NULL. I didn't backport that change. --amk]

  • Participants
  • Parent commits a60495b
  • Branches 2.4

Comments (0)

Files changed (1)

Objects/typeobject.c

 	PyTypeObject *type = self->ob_type;
 	while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE)
 		type = type->tp_base;
-	if (type->tp_setattro != func) {
+	/* If type is NULL now, this is a really weird type.
+	   In the spirit of backwards compatibility (?), just shut up. */
+	if (type && type->tp_setattro != func) {
 		PyErr_Format(PyExc_TypeError,
 			     "can't apply this %s to %s object",
 			     what,
 	staticbase = subtype;
 	while (staticbase && (staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE))
 		staticbase = staticbase->tp_base;
-	if (staticbase->tp_new != type->tp_new) {
+	/* If staticbase is NULL now, this is a really weird type.
+	   In the spirit of backwards compatibility (?), just shut up. */
+	if (staticbase && staticbase->tp_new != type->tp_new) {
 		PyErr_Format(PyExc_TypeError,
 			     "%s.__new__(%s) is not safe, use %s.__new__()",
 			     type->tp_name,