summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-13 13:22:24 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-13 13:22:24 +0100
commit9b7a8ee8f1032a1c9172afe0bd3ac5be7780e4a2 (patch)
tree79b3b74827761d1db8b2081a2e1e2be24322a527 /py/objlist.c
parent9d02780eafd9546354fd3ac429b0211f52331650 (diff)
downloadmicropython-9b7a8ee8f1032a1c9172afe0bd3ac5be7780e4a2.tar.gz
micropython-9b7a8ee8f1032a1c9172afe0bd3ac5be7780e4a2.zip
py: Fix mult by negative number of tuple, list, str, bytes.
Multiplication of a tuple, list, str or bytes now yields an empty sequence (instead of crashing). Addresses issue #799 Also added ability to mult bytes on LHS by integer.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 655a78908e..578e39452a 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -131,6 +131,9 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
if (!mp_obj_get_int_maybe(rhs, &n)) {
return MP_OBJ_NULL; // op not supported
}
+ if (n < 0) {
+ n = 0;
+ }
mp_obj_list_t *s = list_new(o->len * n);
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
return s;