summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-01-10 10:54:19 +0800
committerXiang Zhang <angwerzx@126.com>2017-01-10 10:54:19 +0800
commit199170cc6d4b1c15333c263567004dfd6bd41446 (patch)
tree696d119f3744841995d77d00a15b53d3585c4dc6 /Objects
parent35e3dd49de9618fa26d2c26ecd8506c04ef633f5 (diff)
parent56a31f660633c404ea934e133a614b051b89a436 (diff)
downloadcpython-199170cc6d4b1c15333c263567004dfd6bd41446.tar.gz
Issue #29145: Merge 3.5.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b0c410cfcf..a5ae454b49 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9988,7 +9988,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,
@@ -9999,16 +9999,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;
@@ -10646,7 +10648,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;