diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-10-01 04:12:20 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-10-01 04:12:20 (GMT) |
commit | 5c0fb00ad80d6c70a9a51f3e3d2c1bfcecbd0840 (patch) | |
tree | ac7ae0ee1e40736073c3ea37c0e33051339ee825 /Objects | |
parent | 31616ea2ffca7a1603c9f5941cfca2f1330028f3 (diff) | |
parent | de636f3c34f326fc7b07e4288d411be38d2a299c (diff) | |
download | cpython-5c0fb00ad80d6c70a9a51f3e3d2c1bfcecbd0840.zip cpython-5c0fb00ad80d6c70a9a51f3e3d2c1bfcecbd0840.tar.gz cpython-5c0fb00ad80d6c70a9a51f3e3d2c1bfcecbd0840.tar.bz2 |
merge heads
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/unicodeobject.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 9971f5c..51cd855 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -10446,6 +10446,11 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end) int kind; Py_ssize_t length; + if (PyUnicode_READY(self) == -1) + return NULL; + + end = Py_MIN(end, PyUnicode_GET_LENGTH(self)); + if (start == 0 && end == PyUnicode_GET_LENGTH(self)) { if (PyUnicode_CheckExact(self)) { @@ -10460,13 +10465,11 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end) if (length == 1) return unicode_getitem((PyUnicodeObject*)self, start); - if (start < 0 || end < 0 || end > PyUnicode_GET_LENGTH(self)) { + if (start < 0 || end < 0) { PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } - if (PyUnicode_READY(self) == -1) - return NULL; kind = PyUnicode_KIND(self); data = PyUnicode_1BYTE_DATA(self); return PyUnicode_FromKindAndData(kind, |