driver: display: Added asserts to write of dummy driver

Added asserts to write function of dummy 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:40:59 +02:00 committed by Carles Cufí
commit 814f94e053

View file

@ -29,6 +29,22 @@ static int dummy_display_write(const struct device *dev, const uint16_t x,
const struct display_buffer_descriptor *desc,
const void *buf)
{
__ASSERT(desc->width <= desc->pitch, "Pitch is smaller then width");
__ASSERT(desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
"Pitch in descriptor is larger than screen size");
__ASSERT(desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
"Height in descriptor is larger than screen size");
__ASSERT(x + desc->pitch <= CONFIG_DUMMY_DISPLAY_X_RES,
"Writing outside screen boundaries in horizontal direction");
__ASSERT(y + desc->height <= CONFIG_DUMMY_DISPLAY_Y_RES,
"Writing outside screen boundaries in vertical direction");
if (desc->width > desc->pitch ||
x + desc->pitch > CONFIG_DUMMY_DISPLAY_X_RES ||
y + desc->height > CONFIG_DUMMY_DISPLAY_Y_RES) {
return -EINVAL;
}
return 0;
}