summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-01 01:55:54 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-01 01:55:54 (GMT)
commitde636f3c34f326fc7b07e4288d411be38d2a299c (patch)
tree52c625acfbd142910b574b925a21b0250de88c1f /Objects
parent9f789e7f63809302b887a5fff8e186768c6d3a16 (diff)
downloadcpython-de636f3c34f326fc7b07e4288d411be38d2a299c.zip
cpython-de636f3c34f326fc7b07e4288d411be38d2a299c.tar.gz
cpython-de636f3c34f326fc7b07e4288d411be38d2a299c.tar.bz2
PyUnicode_Substring() now accepts end bigger than string length
Fix also a bug: call PyUnicode_READY() before reading string length.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 92208f4..e42e824 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10447,6 +10447,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)) {
@@ -10461,13 +10466,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,