]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r50680 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 18:40:23 +0000 (18:40 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 18:40:23 +0000 (18:40 +0000)
Handle a NULL name properly.

Objects/fileobject.c

index 16499eec9f0bd408814c335887bee7edda9d8bea..4f5720cde195a7df2830ee1ca060203f6f0cdc54 100644 (file)
@@ -328,11 +328,11 @@ file_repr(PyFileObject *f)
        if (PyUnicode_Check(f->f_name)) {
 #ifdef Py_USING_UNICODE
                PyObject *ret = NULL;
-               PyObject *name;
-               name = PyUnicode_AsUnicodeEscapeString(f->f_name);
+               PyObject *name = PyUnicode_AsUnicodeEscapeString(f->f_name);
+               const char *name_str = name ? PyString_AsString(name) : "?";
                ret = PyString_FromFormat("<%s file u'%s', mode '%s' at %p>",
                                   f->f_fp == NULL ? "closed" : "open",
-                                  PyString_AsString(name),
+                                  name_str,
                                   PyString_AsString(f->f_mode),
                                   f);
                Py_XDECREF(name);