Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 76723:99be985edeca
Fix PyUnicode_Substring() for start >= length and start > end
Remove the fast-path for 1-character string: unicode_fromascii() and
_PyUnicode_FromUCS*() now have their own fast-path for 1-character strings.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Thu, 03 May 2012 02:32:34 +0200 |
| parents | 3d83e2297166 |
| children | 69ed936deb0f |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Thu May 03 02:17:04 2012 +0200 +++ b/Objects/unicodeobject.c Thu May 03 02:32:34 2012 +0200 @@ -12067,20 +12067,22 @@ if (PyUnicode_READY(self) == -1) return NULL; - end = Py_MIN(end, PyUnicode_GET_LENGTH(self)); - - if (start == 0 && end == PyUnicode_GET_LENGTH(self)) + length = PyUnicode_GET_LENGTH(self); + end = Py_MIN(end, length); + + if (start == 0 && end == length) return unicode_result_unchanged(self); - length = end - start; - if (length == 1) - return unicode_getitem(self, start); - if (start < 0 || end < 0) { PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } - + if (start >= length || end < start) { + assert(end == length); + return PyUnicode_New(0, 0); + } + + length = end - start; if (PyUnicode_IS_ASCII(self)) { data = PyUnicode_1BYTE_DATA(self); return unicode_fromascii(data + start, length);
