]> granicus.if.org Git - python/commitdiff
Fixed some details of printing the str() of an exception. This fixes
authorGuido van Rossum <guido@python.org>
Fri, 5 Sep 1997 19:11:53 +0000 (19:11 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 5 Sep 1997 19:11:53 +0000 (19:11 +0000)
a core dump when __str__() returns a non-string, and plugs a memory
leak as well: the result of PyObject_Str() was never DECREFed.

Python/pythonrun.c

index c7832dc3843a344a3b46484e4ba44e64b95fbfd5..610ec7a1f50ba9a461493cf3dc695a7122368590 100644 (file)
@@ -761,10 +761,14 @@ PyErr_Print()
                                /* only print colon if the str() of the
                                   object is not the empty string
                                */
-                               if (s && strcmp(PyString_AsString(s), ""))
+                               if (s == NULL)
+                                       err = -1;
+                               else if (!PyString_Check(s) ||
+                                        PyString_GET_SIZE(s) != 0)
                                        err = PyFile_WriteString(": ", f);
                                if (err == 0)
-                                 err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
+                                 err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
+                               Py_XDECREF(s);
                        }
                }
                if (err == 0)