8000 py/objint_longlong: Check for zero division/modulo. · lvgl/lv_micropython@c0877cb · GitHub
[go: up one dir, main page]

Skip to content

Commit c0877cb

Browse files
committed
py/objint_longlong: Check for zero division/modulo.
1 parent e9d29c9 commit c0877cb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

py/objint_longlong.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,15 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
151151
return mp_obj_new_int_from_ll(lhs_val * rhs_val);
152152
case MP_BINARY_OP_FLOOR_DIVIDE:
153153
case MP_BINARY_OP_INPLACE_FLOOR_DIVIDE:
154+
if (rhs_val == 0) {
155+
goto zero_division;
156+
}
154157
return mp_obj_new_int_from_ll(lhs_val / rhs_val);
155158
case MP_BINARY_OP_MODULO:
156159
case MP_BINARY_OP_INPLACE_MODULO:
160+
if (rhs_val == 0) {
161+
goto zero_division;
162+
}
157163
return mp_obj_new_int_from_ll(lhs_val % rhs_val);
158164

159165
case MP_BINARY_OP_AND:
@@ -210,6 +216,9 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i
210216
default:
211217
return MP_OBJ_NULL; // op not supported
212218
}
219+
220+
zero_division:
221+
mp_raise_msg(&mp_type_ZeroDivisionError, "division by zero");
213222
}
214223

215224
mp_obj_t mp_obj_new_int(mp_int_t value) {

0 commit comments

Comments
 (0)
0