diff options
| author | Damien George <damien@micropython.org> | 2023-01-23 12:24:39 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-01-23 13:03:51 +1100 |
| commit | d387ae3444751a3ba1032bd16243cb2dc741e333 (patch) | |
| tree | 73a885555bb9433bcb2b3810540e544d21808950 | |
| parent | d4a4cde42e80dc2c25c018af200e641b03999e19 (diff) | |
py/objint_mpz: Catch and reject @ and @= operating on big integers.
This will also catch / and /= when float support is disabled.
Fixes issue #10544.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | py/objint_mpz.c | 6 | ||||
| -rw-r--r-- | tests/basics/int_big_error.py | 10 |
2 files changed, 14 insertions, 2 deletions
diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 2811bcf2a..e9545149f 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -296,8 +296,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i mpz_pow_inpl(&res->mpz, zlhs, zrhs); break; - default: { - assert(op == MP_BINARY_OP_DIVMOD); + case MP_BINARY_OP_DIVMOD: { if (mpz_is_zero(zrhs)) { goto zero_division_error; } @@ -306,6 +305,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i mp_obj_t tuple[2] = {MP_OBJ_FROM_PTR(quo), MP_OBJ_FROM_PTR(res)}; return mp_obj_new_tuple(2, tuple); } + + default: + return MP_OBJ_NULL; // op not supported } return MP_OBJ_FROM_PTR(res); diff --git a/tests/basics/int_big_error.py b/tests/basics/int_big_error.py index 79809aef1..1793cf325 100644 --- a/tests/basics/int_big_error.py +++ b/tests/basics/int_big_error.py @@ -8,6 +8,16 @@ except ValueError: print("ValueError") try: + i @ 0 +except TypeError: + print("TypeError") + +try: + i @= 0 +except TypeError: + print("TypeError") + +try: len(i) except TypeError: print("TypeError") |
