diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-09-20 17:22:58 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-09-20 17:22:58 (GMT) |
commit | 3508e308613055ea28bfb766828f03cc08a6789b (patch) | |
tree | af687cb55be863ce0a3db628f2e3c9e78a6c389c /Objects/unicodeobject.c | |
parent | 5e89bd656f6cb48ada3547af4303a923902145e8 (diff) | |
download | cpython-3508e308613055ea28bfb766828f03cc08a6789b.zip cpython-3508e308613055ea28bfb766828f03cc08a6789b.tar.gz cpython-3508e308613055ea28bfb766828f03cc08a6789b.tar.bz2 |
Fix Unicode .join() method to raise a TypeError for sequence
elements which are not Unicode objects or strings. (This matches
the string.join() behaviour.)
Fix a memory leak in the .join() method which occurs in case
the Unicode resize fails.
Restore the test_unicode output.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 896e80f..c8c07a6 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3197,6 +3197,14 @@ PyObject *PyUnicode_Join(PyObject *separator, } if (!PyUnicode_Check(item)) { PyObject *v; + if (!PyString_Check(item)) { + PyErr_Format(PyExc_TypeError, + "sequence item %i: expected string or Unicode," + " %.80s found", + i, item->ob_type->tp_name); + Py_DECREF(item); + goto onError; + } v = PyUnicode_FromObject(item); Py_DECREF(item); item = v; @@ -3205,8 +3213,10 @@ PyObject *PyUnicode_Join(PyObject *separator, } itemlen = PyUnicode_GET_SIZE(item); while (reslen + itemlen + seplen >= sz) { - if (_PyUnicode_Resize(&res, sz*2)) + if (_PyUnicode_Resize(&res, sz*2)) { + Py_DECREF(item); goto onError; + } sz *= 2; p = PyUnicode_AS_UNICODE(res) + reslen; } |