summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-09-30 03:02:35 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-09-30 03:02:35 (GMT)
commit43030ee78041455566e7f78d6d5135eaa3455294 (patch)
tree070432959d5a68bb8d36e08759ae3a073619706d /Objects/unicodeobject.c
parentc44eb73473f31dfde1e8cb6ba485a309e3b0757e (diff)
parent736b8012b42be24dd26b57bd443a576cc37c116c (diff)
downloadcpython-43030ee78041455566e7f78d6d5135eaa3455294.zip
cpython-43030ee78041455566e7f78d6d5135eaa3455294.tar.gz
cpython-43030ee78041455566e7f78d6d5135eaa3455294.tar.bz2
merge 3.3 (#22520)
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 3da09ef..c3f75fd 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -12341,28 +12341,34 @@ unicode_repr(PyObject *unicode)
ikind = PyUnicode_KIND(unicode);
for (i = 0; i < isize; i++) {
Py_UCS4 ch = PyUnicode_READ(ikind, idata, i);
+ Py_ssize_t incr = 1;
switch (ch) {
- case '\'': squote++; osize++; break;
- case '"': dquote++; osize++; break;
+ case '\'': squote++; break;
+ case '"': dquote++; break;
case '\\': case '\t': case '\r': case '\n':
- osize += 2; break;
+ incr = 2;
+ break;
default:
/* Fast-path ASCII */
if (ch < ' ' || ch == 0x7f)
- osize += 4; /* \xHH */
+ incr = 4; /* \xHH */
else if (ch < 0x7f)
- osize++;
- else if (Py_UNICODE_ISPRINTABLE(ch)) {
- osize++;
+ ;
+ else if (Py_UNICODE_ISPRINTABLE(ch))
max = ch > max ? ch : max;
- }
else if (ch < 0x100)
- osize += 4; /* \xHH */
+ incr = 4; /* \xHH */
else if (ch < 0x10000)
- osize += 6; /* \uHHHH */
+ incr = 6; /* \uHHHH */
else
- osize += 10; /* \uHHHHHHHH */
+ incr = 10; /* \uHHHHHHHH */
+ }
+ if (osize > PY_SSIZE_T_MAX - incr) {
+ PyErr_SetString(PyExc_OverflowError,
+ "string is too long to generate repr");
+ return NULL;
}
+ osize += incr;
}
quote = '\'';