Skip to content

Commit 3792581

Browse files
authored
Merge pull request adafruit#1548 from tannewt/shape_arg_check
Arg check width and height into Shape.
2 parents f99b9dd + b13adfc commit 3792581

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

shared-bindings/bleio/CharacteristicBuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type,
7676

7777
const int buffer_size = args[ARG_buffer_size].u_int;
7878
if (buffer_size < 1) {
79-
mp_raise_ValueError(translate("buffer_size must be >= 1"));
79+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_buffer_size);
8080
}
8181

8282
if (!MP_OBJ_IS_TYPE(characteristic, &bleio_characteristic_type)) {

shared-bindings/displayio/Shape.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@ STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_arg
6464
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
6565
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
6666

67+
mp_int_t width = args[ARG_width].u_int;
68+
if (width < 1) {
69+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_width);
70+
}
71+
mp_int_t height = args[ARG_height].u_int;
72+
if (height < 1) {
73+
mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_height);
74+
}
75+
6776
displayio_shape_t *self = m_new_obj(displayio_shape_t);
6877
self->base.type = &displayio_shape_type;
6978
common_hal_displayio_shape_construct(self,
70-
args[ARG_width].u_int,
71-
args[ARG_height].u_int,
79+
width,
80+
height,
7281
args[ARG_mirror_x].u_bool,
7382
args[ARG_mirror_y].u_bool);
7483

0 commit comments

Comments
 (0)