mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Also improve error message on overflow.
This commit is contained in:
parent
6946ea0be0
commit
90e27d38f5
3 changed files with 6 additions and 4 deletions
|
@ -1788,7 +1788,7 @@ string_join(PyStringObject *self, PyObject *orig)
|
|||
sz += seplen;
|
||||
if (sz < old_sz || sz > PY_SSIZE_T_MAX) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"join() is too long for a Python string");
|
||||
"join() result is too long for a Python string");
|
||||
Py_DECREF(seq);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -4491,11 +4491,11 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
|||
/* Make sure we have enough space for the separator and the item. */
|
||||
itemlen = PyUnicode_GET_SIZE(item);
|
||||
new_res_used = res_used + itemlen;
|
||||
if (new_res_used <= 0)
|
||||
if (new_res_used < 0)
|
||||
goto Overflow;
|
||||
if (i < seqlen - 1) {
|
||||
new_res_used += seplen;
|
||||
if (new_res_used <= 0)
|
||||
if (new_res_used < 0)
|
||||
goto Overflow;
|
||||
}
|
||||
if (new_res_used > res_alloc) {
|
||||
|
@ -4536,7 +4536,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
|
|||
|
||||
Overflow:
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"join() is too long for a Python string");
|
||||
"join() result is too long for a Python string");
|
||||
Py_DECREF(item);
|
||||
/* fall through */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue