]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
unicode_fromascii() checks that the input is ASCII in debug mode
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Oct 2011 21:26:01 +0000 (23:26 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 5 Oct 2011 21:26:01 +0000 (23:26 +0200)
Objects/unicodeobject.c

index 134ae29ed71fb6e13de1c42e83544ebf2c59a337..bf2b32a936346d60a27ae8ccc9996b6c372e9c3f 100644 (file)
@@ -1537,12 +1537,20 @@ PyUnicode_FromString(const char *u)
 }
 
 static PyObject*
-unicode_fromascii(const unsigned char* u, Py_ssize_t size)
+unicode_fromascii(const unsigned char* s, Py_ssize_t size)
 {
-    PyObject *res = PyUnicode_New(size, 127);
+    PyObject *res;
+#ifdef Py_DEBUG
+    const unsigned char *p;
+    const unsigned char *end = s + size;
+    for (p=s; p < end; p++) {
+        assert(*p < 128);
+    }
+#endif
+    res = PyUnicode_New(size, 127);
     if (!res)
         return NULL;
-    memcpy(PyUnicode_1BYTE_DATA(res), u, size);
+    memcpy(PyUnicode_1BYTE_DATA(res), s, size);
     return res;
 }