diff -r 30f154d9abf0 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Sun Nov 20 18:01:37 2016 -0800 +++ b/Objects/unicodeobject.c Mon Nov 21 17:23:14 2016 +0800 @@ -6118,12 +6118,7 @@ return result; } -/* Return a Unicode-Escape string version of the Unicode object. - - If quotes is true, the string is enclosed in u"" or u'' quotes as - appropriate. - -*/ +/* Return a Unicode-Escape string version of the Unicode object. */ PyObject * PyUnicode_AsUnicodeEscapeString(PyObject *unicode) @@ -6161,10 +6156,10 @@ /* 4 byte characters can take up 10 bytes, 2 byte characters can take up 6 bytes, and 1 byte characters 4. */ expandsize = kind * 2 + 2; - if (len > (PY_SSIZE_T_MAX - 2 - 1) / expandsize) { + if (len > PY_SSIZE_T_MAX / expandsize) { return PyErr_NoMemory(); } - repr = PyBytes_FromStringAndSize(NULL, 2 + expandsize * len + 1); + repr = PyBytes_FromStringAndSize(NULL, expandsize * len); if (repr == NULL) { return NULL; } @@ -6209,9 +6204,8 @@ *p++ = Py_hexdigits[ch & 0x000F]; } } - /* U+0000-U+00ff range: Map 16-bit characters to '\uHHHH' */ + /* U+0100-U+ffff range: Map 16-bit characters to '\uHHHH' */ else if (ch < 0x10000) { - /* U+0100-U+ffff */ *p++ = '\\'; *p++ = 'u'; *p++ = Py_hexdigits[(ch >> 12) & 0x000F];