mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
merge 3.4 (#23369)
This commit is contained in:
commit
71cf91cc09
3 changed files with 22 additions and 5 deletions
|
@ -182,17 +182,24 @@ ascii_escape_unicode(PyObject *pystr)
|
|||
/* Compute the output size */
|
||||
for (i = 0, output_size = 2; i < input_chars; i++) {
|
||||
Py_UCS4 c = PyUnicode_READ(kind, input, i);
|
||||
if (S_CHAR(c))
|
||||
output_size++;
|
||||
Py_ssize_t d;
|
||||
if (S_CHAR(c)) {
|
||||
d = 1;
|
||||
}
|
||||
else {
|
||||
switch(c) {
|
||||
case '\\': case '"': case '\b': case '\f':
|
||||
case '\n': case '\r': case '\t':
|
||||
output_size += 2; break;
|
||||
d = 2; break;
|
||||
default:
|
||||
output_size += c >= 0x10000 ? 12 : 6;
|
||||
d = c >= 0x10000 ? 12 : 6;
|
||||
}
|
||||
}
|
||||
if (output_size > PY_SSIZE_T_MAX - d) {
|
||||
PyErr_SetString(PyExc_OverflowError, "string is too long to escape");
|
||||
return NULL;
|
||||
}
|
||||
output_size += d;
|
||||
}
|
||||
|
||||
rval = PyUnicode_New(output_size, 127);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue