driver: display: Added extra asserts to SDL display

Added extra asserts to write function of SDL display driver to check if
write is within bounds.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
This commit is contained in:
Jan Van Winkel 2020-07-12 23:43:51 +02:00 committed by Carles Cufí
commit adecdd5d43

View file

@ -225,6 +225,20 @@ static int sdl_display_write(const struct device *dev, const uint16_t x,
desc->height, x, y); desc->height, x, y);
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width"); __ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
__ASSERT(desc->pitch <= CONFIG_SDL_DISPLAY_X_RES,
"Pitch in descriptor is larger than screen size");
__ASSERT(desc->height <= CONFIG_SDL_DISPLAY_Y_RES,
"Height in descriptor is larger than screen size");
__ASSERT(x + desc->pitch <= CONFIG_SDL_DISPLAY_X_RES,
"Writing outside screen boundaries in horizontal direction");
__ASSERT(y + desc->height <= CONFIG_SDL_DISPLAY_Y_RES,
"Writing outside screen boundaries in vertical direction");
if (desc->width > desc->pitch ||
x + desc->pitch > CONFIG_SDL_DISPLAY_X_RES ||
y + desc->height > CONFIG_SDL_DISPLAY_Y_RES) {
return -EINVAL;
}
if (disp_data->current_pixel_format == PIXEL_FORMAT_ARGB_8888) { if (disp_data->current_pixel_format == PIXEL_FORMAT_ARGB_8888) {
sdl_display_write_argb8888(disp_data->buf, desc, buf); sdl_display_write_argb8888(disp_data->buf, desc, buf);