]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 16 Oct 2010 22:55:47 +0000 (22:55 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 16 Oct 2010 22:55:47 +0000 (22:55 +0000)
surrogate characters.

Python/fileutils.c

index 147636f2c78957c5b63cfba64665e2a330453824..b8910b7be640e17a0ead5dcc49262a4dde7b8c0d 100644 (file)
@@ -353,6 +353,7 @@ _Py_wrealpath(const wchar_t *path,
 {
     char *cpath;
     char cresolved_path[PATH_MAX];
+    wchar_t *wresolved_path;
     char *res;
     size_t r;
     cpath = _Py_wchar2char(path);
@@ -364,11 +365,20 @@ _Py_wrealpath(const wchar_t *path,
     PyMem_Free(cpath);
     if (res == NULL)
         return NULL;
-    r = mbstowcs(resolved_path, cresolved_path, resolved_path_size);
-    if (r == (size_t)-1 || r >= PATH_MAX) {
+
+    wresolved_path = _Py_char2wchar(cresolved_path);
+    if (wresolved_path == NULL) {
+        errno = EINVAL;
+        return NULL;
+    }
+    r = wcslen(wresolved_path);
+    if (resolved_path_size <= r) {
+        PyMem_Free(wresolved_path);
         errno = EINVAL;
         return NULL;
     }
+    wcsncpy(resolved_path, wresolved_path, resolved_path_size);
+    PyMem_Free(wresolved_path);
     return resolved_path;
 }
 #endif