summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-10-05 22:40:45 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-10-05 22:40:45 (GMT)
commit8c6db45d3e8a20cabe50f93b2bbc33b0040af5a3 (patch)
tree6bfaa225e3ef2bafc0d9a4f57c4cfa0070a1d4ca /Objects
parent220e869a51ccf49b182ed86680cf10d077afeb36 (diff)
downloadcpython-8c6db45d3e8a20cabe50f93b2bbc33b0040af5a3.zip
cpython-8c6db45d3e8a20cabe50f93b2bbc33b0040af5a3.tar.gz
cpython-8c6db45d3e8a20cabe50f93b2bbc33b0040af5a3.tar.bz2
In debug mode, unicode_write_cstr() now checks that non-ASCII characters are
not written into an ASCII string
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index daeb4b4..84bbf9a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}