Merge pull request #6515 from FoamyGuy/palette_index_fix

palette_index validation in Palette functions
This commit is contained in:
Jeff Epler 2022-06-23 16:49:40 +02:00 committed by GitHub
commit 2b7c81b0e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -160,6 +160,8 @@ STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int"));
}
palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
common_hal_displayio_palette_make_transparent(self, palette_index);
return mp_const_none;
}
@ -175,6 +177,8 @@ STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t pal
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int"));
}
palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
common_hal_displayio_palette_make_opaque(self, palette_index);
return mp_const_none;
}
@ -191,6 +195,8 @@ STATIC mp_obj_t displayio_palette_obj_is_transparent(mp_obj_t self_in, mp_obj_t
if (!mp_obj_get_int_maybe(palette_index_obj, &palette_index)) {
mp_raise_ValueError(translate("palette_index should be an int"));
}
palette_index = mp_arg_validate_int_range(palette_index, 0, common_hal_displayio_palette_get_len(self) - 1, MP_QSTR_palette_index);
return mp_obj_new_bool(common_hal_displayio_palette_is_transparent(self, palette_index));
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_is_transparent_obj, displayio_palette_obj_is_transparent);