Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 72711:2bf53a7e253f
unicode_fromascii() checks that the input is ASCII in debug mode
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 05 Oct 2011 23:26:01 +0200 |
| parents | 05ed6e5f2cf4 |
| children | b2330e70b41e |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Wed Oct 05 22:44:12 2011 +0200 +++ b/Objects/unicodeobject.c Wed Oct 05 23:26:01 2011 +0200 @@ -1537,12 +1537,20 @@ } static PyObject* -unicode_fromascii(const unsigned char* u, Py_ssize_t size) -{ - PyObject *res = PyUnicode_New(size, 127); +unicode_fromascii(const unsigned char* s, Py_ssize_t size) +{ + 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; }
