[Python-checkins] r83332 - python/branches/import_unicode/Python/import.c

victor.stinner python-checkins at python.org
Sat Jul 31 12:31:17 CEST 2010


Author: victor.stinner
Date: Sat Jul 31 12:31:17 2010
New Revision: 83332

Log:
Fix usage of PyUnicode_AsWideChar() and sizeof() in import.c

Last argument is the number of characters, not the number of bytes.

Modified:
   python/branches/import_unicode/Python/import.c

Modified: python/branches/import_unicode/Python/import.c
==============================================================================
--- python/branches/import_unicode/Python/import.c	(original)
+++ python/branches/import_unicode/Python/import.c	Sat Jul 31 12:31:17 2010
@@ -2002,7 +2002,8 @@
     if (Py_GETENV("PYTHONCASEOK") != NULL)
         return 1;
 
-    len = PyUnicode_AsWideChar((PyUnicodeObject*)fullpath_obj, buffer, sizeof(buffer));
+    len = PyUnicode_AsWideChar((PyUnicodeObject*)fullpath_obj, buffer,
+                               sizeof(buffer) / sizeof(buffer[0]));
     if (len == -1)
         return 0;
 
@@ -2138,7 +2139,8 @@
     Py_ssize_t len;
     int usize;
 
-    len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path, sizeof(path));
+    len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path,
+                               sizeof(path) / sizeof(path[0]));
     if (len == -1)
         return NULL;
 
@@ -2172,7 +2174,8 @@
     int err;
     struct _stat wstatbuf;
 
-    len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path, sizeof(path));
+    len = PyUnicode_AsWideChar((PyUnicodeObject*)unicode, path,
+                               sizeof(path) / sizeof(path[0]));
     if (len == -1)
         return -1;
     err = _wstat(path, &wstatbuf);
@@ -3874,7 +3877,7 @@
         wchar_t path[MAXPATHLEN+1];
         Py_ssize_t len;
         len = PyUnicode_AsWideChar((PyUnicodeObject*)pathobj,
-                                   path, sizeof(path));
+                                   path, sizeof(path) / sizeof(path[0]));
         if (len == -1)
             return -1;
         /* see issue1293 and issue3677:


More information about the Python-checkins mailing list