]> granicus.if.org Git - python/commitdiff
PyUnicode_New() sets utf8_length to zero for latin1
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 3 Oct 2011 23:02:02 +0000 (01:02 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 3 Oct 2011 23:02:02 +0000 (01:02 +0200)
Objects/unicodeobject.c

index cad9bfe85f83cd9597c9548cd9588f551695a4b0..87d661e8bece45d2a6af4b5930ed257afa603000 100644 (file)
@@ -755,7 +755,7 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
     PyCompactUnicodeObject *unicode;
     void *data;
     int kind_state;
-    int is_sharing = 0, is_ascii = 0;
+    int is_sharing, is_ascii;
     Py_ssize_t char_size;
     Py_ssize_t struct_size;
 
@@ -769,6 +769,8 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
     ++unicode_new_new_calls;
 #endif
 
+    is_ascii = 0;
+    is_sharing = 0;
     struct_size = sizeof(PyCompactUnicodeObject);
     if (maxchar < 128) {
         kind_state = PyUnicode_1BYTE_KIND;
@@ -833,11 +835,12 @@ PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
         ((char*)data)[size] = 0;
         _PyUnicode_WSTR(unicode) = NULL;
         _PyUnicode_WSTR_LENGTH(unicode) = 0;
-        unicode->utf8_length = 0;
         unicode->utf8 = NULL;
+        unicode->utf8_length = 0;
         }
     else {
         unicode->utf8 = NULL;
+        unicode->utf8_length = 0;
         if (kind_state == PyUnicode_2BYTE_KIND)
             ((Py_UCS2*)data)[size] = 0;
         else /* kind_state == PyUnicode_4BYTE_KIND */