summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-05 21:57:27 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-05 21:57:27 +0000
commitc553162ebcc01765fd1556731ec98067f3981cd5 (patch)
treee4a061f1a4ce17cd9aaa4956ea626b5decafdee1 /py/objlist.c
parent12e2656472bf53e467c066eda6f3e177a97210ca (diff)
downloadmicropython-c553162ebcc01765fd1556731ec98067f3981cd5.tar.gz
micropython-c553162ebcc01765fd1556731ec98067f3981cd5.zip
Fix off-by-one in non-default values of index's 2nd and 3rd arguments.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 6c0de405fe..b52f767eec 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -182,13 +182,17 @@ static mp_obj_t list_index(int n_args, const mp_obj_t *args) {
assert(MP_OBJ_IS_TYPE(args[0], &list_type));
mp_obj_list_t *self = args[0];
mp_obj_t *value = args[1];
+ uint start = 0;
+ uint stop = self->len;
- uint start = mp_get_index(self->base.type, self->len,
- n_args >= 3 ? args[2] : mp_obj_new_int(0));
- uint stop = mp_get_index(self->base.type, self->len,
- n_args >= 4 ? args[3] : mp_obj_new_int(-1));
+ if (n_args >= 3) {
+ start = mp_get_index(self->base.type, self->len, args[2]);
+ if (n_args >= 4) {
+ stop = mp_get_index(self->base.type, self->len, args[3]);
+ }
+ }
- for (uint i = start; i <= stop; i++) {
+ for (uint i = start; i < stop; i++) {
if (mp_obj_equal(self->items[i], value)) {
return mp_obj_new_int(i);
}