]> granicus.if.org Git - python/commitdiff
In debug mode, unicode_write_cstr() now checks that non-ASCII characters are
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 5 Oct 2012 22:40:45 +0000 (00:40 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 5 Oct 2012 22:40:45 +0000 (00:40 +0200)
not written into an ASCII string

Objects/unicodeobject.c

index daeb4b4db56d3dbff3c67d9970b1c4615cd484d0..84bbf9afff91667fa944e312cdf783e1ac334a30 100644 (file)
@@ -1700,6 +1700,14 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index,
     switch (kind) {
     case PyUnicode_1BYTE_KIND: {
         assert(index + len <= PyUnicode_GET_LENGTH(unicode));
+#ifdef Py_DEBUG
+        if (PyUnicode_IS_ASCII(unicode)) {
+            Py_UCS4 maxchar = ucs1lib_find_max_char(
+                (const Py_UCS1*)str,
+                (const Py_UCS1*)str + len);
+            assert(maxchar < 128);
+        }
+#endif
         memcpy((char *) data + index, str, len);
         break;
     }