Skip to content

Commit 7a4da32

Browse files
committed
Issue #29145: Merge 3.6.
2 parents 9ebb245 + 95403d7 commit 7a4da32

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

Objects/stringlib/transmogrify.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ stringlib_replace_interleave(PyObject *self,
261261
assert(count > 0);
262262
if (to_len > (PY_SSIZE_T_MAX - self_len) / count) {
263263
PyErr_SetString(PyExc_OverflowError,
264-
"replace bytes are too long");
264+
"replace bytes is too long");
265265
return NULL;
266266
}
267267
result_len = count * to_len + self_len;

Objects/unicodeobject.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9950,7 +9950,7 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
99509950
use_memcpy = 1;
99519951
#endif
99529952
for (i = 0; i < seqlen; i++) {
9953-
const Py_ssize_t old_sz = sz;
9953+
size_t add_sz;
99549954
item = items[i];
99559955
if (!PyUnicode_Check(item)) {
99569956
PyErr_Format(PyExc_TypeError,
@@ -9961,16 +9961,18 @@ _PyUnicode_JoinArray(PyObject *separator, PyObject **items, Py_ssize_t seqlen)
99619961
}
99629962
if (PyUnicode_READY(item) == -1)
99639963
goto onError;
9964-
sz += PyUnicode_GET_LENGTH(item);
9964+
add_sz = PyUnicode_GET_LENGTH(item);
99659965
item_maxchar = PyUnicode_MAX_CHAR_VALUE(item);
99669966
maxchar = Py_MAX(maxchar, item_maxchar);
9967-
if (i != 0)
9968-
sz += seplen;
9969-
if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
9967+
if (i != 0) {
9968+
add_sz += seplen;
9969+
}
9970+
if (add_sz > (size_t)(PY_SSIZE_T_MAX - sz)) {
99709971
PyErr_SetString(PyExc_OverflowError,
99719972
"join() result is too long for a Python string");
99729973
goto onError;
99739974
}
9975+
sz += add_sz;
99749976
if (use_memcpy && last_obj != NULL) {
99759977
if (PyUnicode_KIND(last_obj) != PyUnicode_KIND(item))
99769978
use_memcpy = 0;
@@ -10608,7 +10610,7 @@ replace(PyObject *self, PyObject *str1,
1060810610
u = unicode_empty;
1060910611
goto done;
1061010612
}
10611-
if (new_size > (PY_SSIZE_T_MAX >> (rkind-1))) {
10613+
if (new_size > (PY_SSIZE_T_MAX / rkind)) {
1061210614
PyErr_SetString(PyExc_OverflowError,
1061310615
"replace string is too long");
1061410616
goto error;

0 commit comments

Comments
 (0)