]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
fileio_init() checks for failure on conversion to Py_UNICODE*
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 29 Sep 2011 21:19:04 +0000 (23:19 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 29 Sep 2011 21:19:04 +0000 (23:19 +0200)
Modules/_io/fileio.c

index 3de1ff5b2dd7c7b578be40c296557a11e77dfeb0..2bf8933b57beb0af43c7d48ca24af2aedced91db 100644 (file)
@@ -259,9 +259,11 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
     }
 
 #ifdef MS_WINDOWS
-    if (PyUnicode_Check(nameobj))
-        widename = PyUnicode_AS_UNICODE(nameobj);
-    if (widename == NULL)
+    if (PyUnicode_Check(nameobj)) {
+        widename = PyUnicode_AsUnicode(nameobj);
+        if (widename == NULL)
+            return -1;
+    } else
 #endif
     if (fd < 0)
     {
@@ -378,7 +380,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
         if (self->fd < 0) {
 #ifdef MS_WINDOWS
             if (widename != NULL)
-                PyErr_SetFromErrnoWithUnicodeFilename(PyExc_IOError, widename);
+                PyErr_SetFromErrnoWithFilenameObject(PyExc_IOError, nameobj);
             else
 #endif
                 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name);