summaryrefslogtreecommitdiff
path: root/py/objtuple.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/objtuple.c
parent9d02780eafd9546354fd3ac429b0211f52331650 (diff)
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/objtuple.c')
-rw-r--r--py/objtuple.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/py/objtuple.c b/py/objtuple.c
index 3dade2f74..377fbf543 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -137,10 +137,13 @@ mp_obj_t mp_obj_tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return s;
}
case MP_BINARY_OP_MULTIPLY: {
- if (!MP_OBJ_IS_SMALL_INT(rhs)) {
+ mp_int_t n;
+ if (!mp_obj_get_int_maybe(rhs, &n)) {
return MP_OBJ_NULL; // op not supported
}
- int n = MP_OBJ_SMALL_INT_VALUE(rhs);
+ if (n <= 0) {
+ return mp_const_empty_tuple;
+ }
mp_obj_tuple_t *s = mp_obj_new_tuple(o->len * n, NULL);
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
return s;