]> granicus.if.org Git - python/commitdiff
_PyUnicode_CheckConsistency() ensures that the unicode string ends with a
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 25 Apr 2012 22:39:37 +0000 (00:39 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 25 Apr 2012 22:39:37 +0000 (00:39 +0200)
null character

Objects/unicodeobject.c

index 7efa939f0f0a00530ad4357a85f85fbacffa2e64..364de90877c24c34c40c32416713e0b946e4cc50 100644 (file)
@@ -375,10 +375,13 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
     {
         Py_ssize_t i;
         Py_UCS4 maxchar = 0;
-        void *data = PyUnicode_DATA(ascii);
+        void *data;
+        Py_UCS4 ch;
+
+        data = PyUnicode_DATA(ascii);
         for (i=0; i < ascii->length; i++)
         {
-            Py_UCS4 ch = PyUnicode_READ(kind, data, i);
+            ch = PyUnicode_READ(kind, data, i);
             if (ch > maxchar)
                 maxchar = ch;
         }
@@ -398,6 +401,7 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
             assert(maxchar >= 0x10000);
             assert(maxchar <= MAX_UNICODE);
         }
+        assert(PyUnicode_READ(kind, data, ascii->length) == 0);
     }
     return 1;
 }