-
Notifications
You must be signed in to change notification settings - Fork 1.4k
displayio, tilepalettemapper, vectorio: arguments narrowed before che… #11382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -45,6 +45,8 @@ static mp_obj_t tilepalettemapper_tilepalettemapper_make_new(const mp_obj_type_t | |||
| mp_raise_TypeError_varg(MP_ERROR_TEXT("unsupported %q type"), MP_QSTR_pixel_shader); | ||||
| } | ||||
|
|
||||
| mp_arg_validate_int_min(args[ARG_input_color_count].u_int, 1, MP_QSTR_input_color_count); | ||||
|
|
||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. input_color_count is
We can validate the top end of the range also instead of just min here. |
||||
| tilepalettemapper_tilepalettemapper_t *self = mp_obj_malloc(tilepalettemapper_tilepalettemapper_t, &tilepalettemapper_tilepalettemapper_type); | ||||
| common_hal_tilepalettemapper_tilepalettemapper_construct(self, pixel_shader, args[ARG_input_color_count].u_int); | ||||
|
|
||||
|
|
@@ -128,9 +130,12 @@ static mp_obj_t tilepalettemapper_subscr(mp_obj_t self_in, mp_obj_t index_obj, m | |||
| } else { | ||||
| uint16_t x = 0; | ||||
| uint16_t y = 0; | ||||
| uint16_t width = common_hal_tilepalettemapper_tilepalettemapper_get_width(self); | ||||
| if (width == 0) { | ||||
| mp_raise_IndexError(MP_ERROR_TEXT("Tile index out of bounds")); | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this check here inside of I think the right time to check the size of the TileGrid would be when it gets bound to the TilePaletteMapper instead of any time square bracket access is used. But I don't think we even need to do that because the width and height of TPM are set to the width and height of the TileGrid it gets bound to, and TileGrid has range enforcement on |
||||
| } | ||||
| if (mp_obj_is_small_int(index_obj)) { | ||||
| mp_int_t i = MP_OBJ_SMALL_INT_VALUE(index_obj); | ||||
| uint16_t width = common_hal_tilepalettemapper_tilepalettemapper_get_width(self); | ||||
| x = i % width; | ||||
| y = i / width; | ||||
| } else { | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ struct _displayio_area_t { | |
| typedef struct { | ||
| uint16_t x; | ||
| uint16_t y; | ||
| int8_t dx; | ||
| int8_t dy; | ||
| uint8_t scale; | ||
| int16_t dx; | ||
| int16_t dy; | ||
| uint16_t scale; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these changed to uint8_t? In the case of |
||
| uint16_t width; | ||
| uint16_t height; | ||
| bool mirror_x; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scale is declared a
uint16_there:circuitpython/shared-module/displayio/Group.h
Line 24 in 82b255f
So, theoretically, up to 65535 would fit in this. Though I do think limiting it to something lower makes sense.
Going even lower than 32767 would be fine with me. I don't know whether it's worth using a smaller sized variable, but for visual practicality anything over a scale of a few dozen or maybe hundreds is going to exceed the "a few pixels are now larger than the displays we support" range.