improving range validation

This commit is contained in:
jposada202020 2023-03-31 20:15:07 -04:00
parent 1931b6c042
commit df46636c5e
2 changed files with 3 additions and 13 deletions

View File

@ -3900,10 +3900,6 @@ msgstr ""
msgid "queue overflow"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c
msgid "radius must be greater than zero"
msgstr ""
#: py/parse.c
msgid "raw f-strings are not supported"
msgstr ""

View File

@ -938,15 +938,9 @@ STATIC mp_obj_t bitmaptools_obj_draw_circle(size_t n_args, const mp_obj_t *pos_a
int16_t y = args[ARG_y].u_int;
int16_t radius = args[ARG_radius].u_int;
if (x < 0 || x >= destination->width) {
mp_raise_ValueError(translate("out of range of target"));
}
if (y < 0 || y >= destination->height) {
mp_raise_ValueError(translate("out of range of target"));
}
if (radius < 0) {
mp_raise_ValueError(translate("radius must be greater than zero"));
}
mp_arg_validate_int_range(x, 0, destination->width, MP_QSTR_x)
mp_arg_validate_int_range(y, 0, destination->height, MP_QSTR_y)
mp_arg_validate_int_min(radius, 0, MP_QSTR_radius)
common_hal_bitmaptools_draw_circle(destination, x, y, radius, value);