[Python-checkins] python/dist/src/Objects unicodeobject.c, 2.229, 2.230

lemburg at users.sourceforge.net lemburg at users.sourceforge.net
Mon Nov 22 14:02:34 CET 2004


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv780/Objects

Modified Files:
	unicodeobject.c 
Log Message:
Correct the handling of 0-termination of PyUnicode_AsWideChar() 
and its usage in PyLocale_strcoll().

Clarify the documentation on this.

Thanks to Andreas Degert for pointing this out.



Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.229
retrieving revision 2.230
diff -u -d -r2.229 -r2.230
--- unicodeobject.c	15 Oct 2004 07:45:05 -0000	2.229
+++ unicodeobject.c	22 Nov 2004 13:02:30 -0000	2.230
@@ -384,8 +384,11 @@
 	PyErr_BadInternalCall();
 	return -1;
     }
+
+    /* If possible, try to copy the 0-termination as well */
     if (size > PyUnicode_GET_SIZE(unicode))
-	size = PyUnicode_GET_SIZE(unicode);
+	size = PyUnicode_GET_SIZE(unicode) + 1;
+
 #ifdef HAVE_USABLE_WCHAR_T
     memcpy(w, unicode->str, size * sizeof(wchar_t));
 #else
@@ -398,6 +401,9 @@
     }
 #endif
 
+    if (size > PyUnicode_GET_SIZE(unicode))
+        return PyUnicode_GET_SIZE(unicode);
+    else
     return size;
 }
 



More information about the Python-checkins mailing list