]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #4071: ntpath.abspath returned an empty string for long unicode path.
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sat, 8 Nov 2008 03:46:17 +0000 (03:46 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Sat, 8 Nov 2008 03:46:17 +0000 (03:46 +0000)
Modules/posixmodule.c

index 39387a92be1ccfd751360b44e132a5bd3b7db212..409974aa2ba2c0fb97f39c2b8c93904182df4718 100644 (file)
@@ -2389,13 +2389,27 @@ posix__getfullpathname(PyObject *self, PyObject *args)
        if (unicode_file_names()) {
                PyUnicodeObject *po;
                if (PyArg_ParseTuple(args, "U|:_getfullpathname", &po)) {
-                       Py_UNICODE woutbuf[MAX_PATH*2];
+                       Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+                       Py_UNICODE woutbuf[MAX_PATH*2], *woutbufp = woutbuf;
                        Py_UNICODE *wtemp;
-                       if (!GetFullPathNameW(PyUnicode_AS_UNICODE(po),
-                                               sizeof(woutbuf)/sizeof(woutbuf[0]),
-                                                woutbuf, &wtemp))
-                               return win32_error("GetFullPathName", "");
-                       return PyUnicode_FromUnicode(woutbuf, wcslen(woutbuf));
+                       DWORD result;
+                       PyObject *v;
+                       result = GetFullPathNameW(wpath,
+                                                  sizeof(woutbuf)/sizeof(woutbuf[0]),
+                                                   woutbuf, &wtemp);
+                       if (result > sizeof(woutbuf)/sizeof(woutbuf[0])) {
+                               woutbufp = malloc(result * sizeof(Py_UNICODE));
+                               if (!woutbufp)
+                                       return PyErr_NoMemory();
+                               result = GetFullPathNameW(wpath, result, woutbufp, &wtemp);
+                       }
+                       if (result)
+                               v = PyUnicode_FromUnicode(woutbufp, wcslen(woutbufp));
+                       else
+                               v = win32_error_unicode("GetFullPathNameW", wpath);
+                       if (woutbufp != woutbuf)
+                               free(woutbufp);
+                       return v;
                }
                /* Drop the argument parsing error as narrow strings
                   are also valid. */