From d387ae3444751a3ba1032bd16243cb2dc741e333 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 23 Jan 2023 12:24:39 +1100 Subject: [PATCH] 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 --- py/objint_mpz.c | 6 ++++-- 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 2811bcf2aa..e9545149f8 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 79809aef11..1793cf3253 100644 --- a/tests/basics/int_big_error.py +++ b/tests/basics/int_big_error.py @@ -7,6 +7,16 @@ try: except ValueError: print("ValueError") +try: + i @ 0 +except TypeError: + print("TypeError") + +try: + i @= 0 +except TypeError: + print("TypeError") + try: len(i) except TypeError: