[Python-checkins] cpython: _PyUnicode_CheckConsistency() ensures that the unicode string ends with a

victor.stinner python-checkins at python.org
Thu Apr 26 00:40:34 CEST 2012


http://hg.python.org/cpython/rev/004f8d96f573
changeset:   76561:004f8d96f573
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Apr 26 00:39:37 2012 +0200
summary:
  _PyUnicode_CheckConsistency() ensures that the unicode string ends with a
null character

files:
  Objects/unicodeobject.c |  8 ++++++--
  1 files changed, 6 insertions(+), 2 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -375,10 +375,13 @@
     {
         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 @@
             assert(maxchar >= 0x10000);
             assert(maxchar <= MAX_UNICODE);
         }
+        assert(PyUnicode_READ(kind, data, ascii->length) == 0);
     }
     return 1;
 }

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list