py: Raise a ValueError if range() step is zero.

Following CPython.  Otherwise one gets either an infinite loop (if code is
optimised by the uPy compiler) or possibly a divide-by-zero CPU exception.
This commit is contained in:
Damien George
2017-04-05 10:50:26 +10:00
parent 546ef301a1
commit de9b53695d
2 changed files with 6 additions and 3 deletions

View File

@@ -105,8 +105,10 @@ STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t
o->start = mp_obj_get_int(args[0]);
o->stop = mp_obj_get_int(args[1]);
if (n_args == 3) {
// TODO check step is non-zero
o->step = mp_obj_get_int(args[2]);
if (o->step == 0) {
mp_raise_ValueError("zero step");
}
}
}