mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-24 00:07:03 +08:00
fix(draw_buf): check range for draw buffer when accessing pixel (#8907)
Signed-off-by: zhouxingjian <zhouxingjian@xiaomi.com>
This commit is contained in:
@@ -379,6 +379,12 @@ void * lv_draw_buf_goto_xy(const lv_draw_buf_t * buf, uint32_t x, uint32_t y)
|
||||
LV_ASSERT_NULL(buf);
|
||||
if(buf == NULL) return NULL;
|
||||
|
||||
if(x >= buf->header.w || y >= buf->header.h) {
|
||||
LV_LOG_ERROR("coordinates out of range, x: %" LV_PRIu32 ", y: %"LV_PRIu32", w: %"LV_PRIu32", h: %"LV_PRIu32, x, y,
|
||||
(uint32_t)buf->header.w, (uint32_t)buf->header.h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t * data = buf->data;
|
||||
|
||||
/*Skip palette*/
|
||||
|
||||
@@ -114,4 +114,17 @@ void test_draw_buf_stride_adjust(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_draw_buf_xy_access(void)
|
||||
{
|
||||
LV_DRAW_BUF_DEFINE_STATIC(draw_buf, 100, 100, LV_COLOR_FORMAT_RGB565);
|
||||
LV_DRAW_BUF_INIT_STATIC(draw_buf);
|
||||
|
||||
uint8_t * ret = lv_draw_buf_goto_xy(&draw_buf, 50, 50);
|
||||
TEST_ASSERT_NOT_NULL(ret);
|
||||
ret = lv_draw_buf_goto_xy(&draw_buf, 100, 100);
|
||||
TEST_ASSERT_NULL(ret);
|
||||
ret = lv_draw_buf_goto_xy(&draw_buf, -10, -10);
|
||||
TEST_ASSERT_NULL(ret);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user