@@ -212,8 +212,9 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
212
212
213
213
displayio_bitmap_t * self = MP_OBJ_TO_PTR (pos_args [0 ]);
214
214
215
- int16_t x = args [ARG_x ].u_int ;
216
- int16_t y = args [ARG_y ].u_int ;
215
+ // Check x,y are within self (target) bitmap boundary
216
+ int16_t x = mp_arg_validate_int_range (args [ARG_x ].u_int , 0 , self -> width - 1 , MP_QSTR_x );
217
+ int16_t y = mp_arg_validate_int_range (args [ARG_y ].u_int , 0 , self -> height - 1 , MP_QSTR_y );
217
218
218
219
displayio_bitmap_t * source = mp_arg_validate_type (args [ARG_source ].u_obj , & displayio_bitmap_type , MP_QSTR_source_bitmap );
219
220
@@ -223,32 +224,21 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg
223
224
mp_raise_ValueError (translate ("source palette too large" ));
224
225
}
225
226
226
- int16_t x1 = args [ARG_x1 ].u_int ;
227
- int16_t y1 = args [ARG_y1 ].u_int ;
227
+ // Check x1,y1,x2,y2 are within source bitmap boundary
228
+ int16_t x1 = mp_arg_validate_int_range (args [ARG_x1 ].u_int , 0 , source -> width - 1 , MP_QSTR_x1 );
229
+ int16_t y1 = mp_arg_validate_int_range (args [ARG_y1 ].u_int , 0 , source -> height - 1 , MP_QSTR_y1 );
228
230
int16_t x2 , y2 ;
229
231
// if x2 or y2 is None, then set as the maximum size of the source bitmap
230
232
if (args [ARG_x2 ].u_obj == mp_const_none ) {
231
233
x2 = source -> width ;
232
234
} else {
233
- x2 = mp_obj_get_int (args [ARG_x2 ].u_obj );
235
+ x2 = mp_arg_validate_int_range ( mp_obj_get_int (args [ARG_x2 ].u_obj ), 0 , source -> width , MP_QSTR_x2 );
234
236
}
235
237
// int16_t y2;
236
238
if (args [ARG_y2 ].u_obj == mp_const_none ) {
237
239
y2 = source -> height ;
238
240
} else {
239
- y2 = mp_obj_get_int (args [ARG_y2 ].u_obj );
240
- }
241
-
242
- // Check x,y are within self (target) bitmap boundary
243
- if ((x < 0 ) || (y < 0 ) || (x > self -> width ) || (y > self -> height )) {
244
- mp_raise_ValueError (translate ("out of range of target" ));
245
- }
246
- // Check x1,y1,x2,y2 are within source bitmap boundary
247
- if ((x1 < 0 ) || (x1 > source -> width ) ||
248
- (y1 < 0 ) || (y1 > source -> height ) ||
249
- (x2 < 0 ) || (x2 > source -> width ) ||
250
- (y2 < 0 ) || (y2 > source -> height )) {
251
- mp_raise_ValueError (translate ("out of range of source" ));
241
+ y2 = mp_arg_validate_int_range (mp_obj_get_int (args [ARG_y2 ].u_obj ), 0 , source -> height , MP_QSTR_y2 );
252
242
}
253
243
254
244
// Ensure x1 < x2 and y1 < y2
0 commit comments