diff options
author | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
---|---|---|
committer | Xiang Zhang <angwerzx@126.com> | 2016-12-20 14:52:33 (GMT) |
commit | b211068f5c8e2535ab2dd7f4c43325bbf5b30fad (patch) | |
tree | d18683bf67a43286f7184b39a8e3b49f036cc466 /Objects | |
parent | 38f225dd486ab69779eab3cae4fa2375f6c2d8d6 (diff) | |
download | cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.zip cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.gz cpython-b211068f5c8e2535ab2dd7f4c43325bbf5b30fad.tar.bz2 |
Issue #28822: Adjust indices handling of PyUnicode_FindChar().
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3fdce82..bbda4d8 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9461,16 +9461,12 @@ PyUnicode_FindChar(PyObject *str, Py_UCS4 ch, int direction) { int kind; - Py_ssize_t result; + Py_ssize_t len, result; if (PyUnicode_READY(str) == -1) return -2; - if (start < 0 || end < 0) { - PyErr_SetString(PyExc_IndexError, "string index out of range"); - return -2; - } - if (end > PyUnicode_GET_LENGTH(str)) - end = PyUnicode_GET_LENGTH(str); - if (start >= end) + len = PyUnicode_GET_LENGTH(str); + ADJUST_INDICES(start, end, len); + if (end - start < 1) return -1; kind = PyUnicode_KIND(str); result = findchar(PyUnicode_1BYTE_DATA(str) + kind*start, |