Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c6db45

Browse files
committed
In debug mode, unicode_write_cstr() now checks that non-ASCII characters are
not written into an ASCII string
1 parent 220e869 commit 8c6db45

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Objects/unicodeobject.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,14 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index,
17001700
switch (kind) {
17011701
case PyUnicode_1BYTE_KIND: {
17021702
assert(index + len <= PyUnicode_GET_LENGTH(unicode));
1703+
#ifdef Py_DEBUG
1704+
if (PyUnicode_IS_ASCII(unicode)) {
1705+
Py_UCS4 maxchar = ucs1lib_find_max_char(
1706+
(const Py_UCS1*)str,
1707+
(const Py_UCS1*)str + len);
1708+
assert(maxchar < 128);
1709+
}
1710+
#endif
17031711
memcpy((char *) data + index, str, len);
17041712
break;
17051713
}

0 commit comments

Comments
 (0)