[Python-checkins] r85581 - python/branches/py3k/Python/fileutils.c

victor.stinner python-checkins at python.org
Sun Oct 17 00:55:48 CEST 2010


Author: victor.stinner
Date: Sun Oct 17 00:55:47 2010
New Revision: 85581

Log:
_Py_wrealpath() uses _Py_char2wchar() to decode the result, to support
surrogate characters.


Modified:
   python/branches/py3k/Python/fileutils.c

Modified: python/branches/py3k/Python/fileutils.c
==============================================================================
--- python/branches/py3k/Python/fileutils.c	(original)
+++ python/branches/py3k/Python/fileutils.c	Sun Oct 17 00:55:47 2010
@@ -353,6 +353,7 @@
 {
     char *cpath;
     char cresolved_path[PATH_MAX];
+    wchar_t *wresolved_path;
     char *res;
     size_t r;
     cpath = _Py_wchar2char(path);
@@ -364,11 +365,20 @@
     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


More information about the Python-checkins mailing list