diff options
author | Guido van Rossum <guido@python.org> | 2003-06-17 14:25:14 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-06-17 14:25:14 (GMT) |
commit | 2743d87d7934535f16a0ea062a28c21ea18e5a24 (patch) | |
tree | a900db61838c03a5371be0edb71895078fc17e15 /Objects | |
parent | 77cdeaff556447a980fe8632e8cd010499ade2d0 (diff) | |
download | cpython-2743d87d7934535f16a0ea062a28c21ea18e5a24.zip cpython-2743d87d7934535f16a0ea062a28c21ea18e5a24.tar.gz cpython-2743d87d7934535f16a0ea062a28c21ea18e5a24.tar.bz2 |
Fix sloppy index() implementation:
- don't use min() and max()
- interpret negative start/stop argument like negative slice indices
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 3979006..a70ac5f 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1834,8 +1834,18 @@ listindex(PyListObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|ii:index", &v, &start, &stop)) return NULL; - start = max(0, start); - stop = max(0, min(self->ob_size, stop)); + if (start < 0) { + start += self->ob_size; + if (start < 0) + start = 0; + } + if (stop < 0) { + stop += self->ob_size; + if (stop < 0) + stop = 0; + } + else if (stop > self->ob_size) + stop = self->ob_size; for (i = start; i < stop; i++) { int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ); if (cmp > 0) |