cpython: bfd8b5d35f9c (original) (raw)
Mercurial > cpython
changeset 72623:bfd8b5d35f9c
PyUnicode_Join() checks output length in debug mode PyUnicode_CopyCharacters() may copies less character than requested size, if the input string is smaller than the argument. (This is very unlikely, but who knows!?) Avoid also calling PyUnicode_CopyCharacters() if the string is empty.
Victor Stinner victor.stinner@haypocalc.com | |
---|---|
date | Mon, 03 Oct 2011 23:36:02 +0200 |
parents | bf6dbd1b10b4 |
children | 65ff63a8347b |
files | Objects/unicodeobject.c |
diffstat | 1 files changed, 22 insertions(+), 10 deletions(-)[+] [-] Objects/unicodeobject.c 32 |
line wrap: on
line diff
--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8890,20 +8890,32 @@ PyUnicode_Join(PyObject separator, PyOb / Catenate everything. */ for (i = 0, res_offset = 0; i < seqlen; ++i) {
Py_ssize_t itemlen;[](#l1.7)
Py_ssize_t itemlen, copied;[](#l1.8) item = items[i];[](#l1.9)
itemlen = PyUnicode_GET_LENGTH(item);[](#l1.10) /* Copy item, and maybe the separator. */[](#l1.11)
if (i) {[](#l1.12)
if (PyUnicode_CopyCharacters(res, res_offset,[](#l1.13)
sep, 0, seplen) < 0)[](#l1.14)
if (i && seplen != 0) {[](#l1.15)
copied = PyUnicode_CopyCharacters(res, res_offset,[](#l1.16)
sep, 0, seplen);[](#l1.17)
if (copied < 0)[](#l1.18) goto onError;[](#l1.19)
res_offset += copied;[](#l1.21)
}[](#l1.24)
if (PyUnicode_CopyCharacters(res, res_offset,[](#l1.25)
item, 0, itemlen) < 0)[](#l1.26)
goto onError;[](#l1.27)
res_offset += itemlen;[](#l1.28)
}[](#l1.30)
itemlen = PyUnicode_GET_LENGTH(item);[](#l1.31)
if (itemlen != 0) {[](#l1.32)
copied = PyUnicode_CopyCharacters(res, res_offset,[](#l1.33)
item, 0, itemlen);[](#l1.34)
if (copied < 0)[](#l1.35)
goto onError;[](#l1.36)
res_offset += copied;[](#l1.38)
res_offset += itemlen;[](#l1.40)