diff options
author | Georg Brandl <georg@python.org> | 2006-06-10 06:40:50 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-06-10 06:40:50 (GMT) |
commit | 90e27d38f5ec7c435d32e1eebe0b7a3ad6b60216 (patch) | |
tree | 157132e2091bf19d163e1f49a43905f7a06b0306 | |
parent | 6946ea0be032c17689ee35d3281060b8fe662471 (diff) | |
download | cpython-90e27d38f5ec7c435d32e1eebe0b7a3ad6b60216.zip cpython-90e27d38f5ec7c435d32e1eebe0b7a3ad6b60216.tar.gz cpython-90e27d38f5ec7c435d32e1eebe0b7a3ad6b60216.tar.bz2 |
Apply perky's fix for #1503157: "/".join([u"", u""]) raising OverflowError.
Also improve error message on overflow.
-rw-r--r-- | Lib/test/string_tests.py | 2 | ||||
-rw-r--r-- | Objects/stringobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 6 |
3 files changed, 6 insertions, 4 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 5a1cc8a..236c529 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -938,6 +938,8 @@ class MixinStrUnicodeUserStringTest: # test.test_string.StringTest.test_join) self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd']) self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd')) + self.checkequal('bd', '', 'join', ('', 'b', '', 'd')) + self.checkequal('ac', '', 'join', ('a', '', 'c', '')) self.checkequal('w x y z', ' ', 'join', Sequence()) self.checkequal('abc', 'a', 'join', ('abc',)) self.checkequal('z', 'a', 'join', UserList(['z'])) diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 831d54a..a5c8cc2 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -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; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index bf2425c..064caeb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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 */ |