summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-01-10 02:56:38 (GMT)
committerXiang Zhang <angwerzx@126.com>2017-01-10 02:56:38 (GMT)
commit7a4da324dc441687dd38c360343698cdaa4c6014 (patch)
tree7c1370b20e8073c4e0acdb66591276ce32556ef9 /Objects/unicodeobject.c
parent9ebb245db821910663f2ec7a9579fd8a68da325c (diff)
parent95403d74d7d17f51b50e68a10e0a0972ed77aa2a (diff)
downloadcpython-7a4da324dc441687dd38c360343698cdaa4c6014.zip
cpython-7a4da324dc441687dd38c360343698cdaa4c6014.tar.gz
cpython-7a4da324dc441687dd38c360343698cdaa4c6014.tar.bz2
Issue #29145: Merge 3.6.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index ef396fb..e322c0c 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9950,7 +9950,7 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
use_memcpy = 1;
#endif
for (i = 0; i < seqlen; i++) {
- const Py_ssize_t old_sz = sz;
+ size_t add_sz;
item = items[i];
if (!PyUnicode_Check(item)) {
PyErr_Format(PyExc_TypeError,
@@ -9961,16 +9961,18 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
}
if (PyUnicode_READY(item) == -1)
goto onError;
- sz += PyUnicode_GET_LENGTH(item);
+ add_sz = PyUnicode_GET_LENGTH(item);
item_maxchar = PyUnicode_MAX_CHAR_VALUE(item);
maxchar = Py_MAX(maxchar, item_maxchar);
- if (i != 0)
- sz += seplen;
- if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
+ if (i != 0) {
+ add_sz += seplen;
+ }
+ if (add_sz > (size_t)(PY_SSIZE_T_MAX - sz)) {
PyErr_SetString(PyExc_OverflowError,
"join() result is too long for a Python string");
goto onError;
}
+ sz += add_sz;
if (use_memcpy && last_obj != NULL) {
if (PyUnicode_KIND(last_obj) != PyUnicode_KIND(item))
use_memcpy = 0;
@@ -10608,7 +10610,7 @@ replace(PyObject *self, PyObject *str1,
u = unicode_empty;
goto done;
}
- if (new_size > (PY_SSIZE_T_MAX >> (rkind-1))) {
+ if (new_size > (PY_SSIZE_T_MAX / rkind)) {
PyErr_SetString(PyExc_OverflowError,
"replace string is too long");
goto error;