diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-05 23:26:01 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-10-05 23:26:01 +0200 |
commit | 0617b6e18b84d854b0648e0893b62a893b7638fd (patch) | |
tree | fb8a9c001accef12684f9f37e0ee55a1bfa12158 | |
parent | a336de7ae1c9d836265fc053018c0f11fc804b9a (diff) | |
download | cpython-git-0617b6e18b84d854b0648e0893b62a893b7638fd.tar.gz |
unicode_fromascii() checks that the input is ASCII in debug mode
-rw-r--r-- | Objects/unicodeobject.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 134ae29ed7..bf2b32a936 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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; } |