1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(snapshot): snapshot should fail when buff_size is zero (#4353)

Signed-off-by: Xu Xingliang <xuxingliang@xiaomi.com>
This commit is contained in:
Neo Xu 2023-07-11 02:03:33 +08:00 committed by GitHub
parent 1526dcac73
commit 44a955f138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,7 +103,7 @@ lv_res_t lv_snapshot_take_to_buf(lv_obj_t * obj, lv_color_format_t cf, lv_img_ds
return LV_RES_INV; return LV_RES_INV;
} }
if(lv_snapshot_buf_size_needed(obj, cf) > buff_size) return LV_RES_INV; if(lv_snapshot_buf_size_needed(obj, cf) > buff_size || buff_size == 0) return LV_RES_INV;
/*Width and height determine snapshot image size.*/ /*Width and height determine snapshot image size.*/
lv_coord_t w = lv_obj_get_width(obj); lv_coord_t w = lv_obj_get_width(obj);
@ -153,6 +153,7 @@ lv_img_dsc_t * lv_snapshot_take(lv_obj_t * obj, lv_color_format_t cf)
{ {
LV_ASSERT_NULL(obj); LV_ASSERT_NULL(obj);
uint32_t buff_size = lv_snapshot_buf_size_needed(obj, cf); uint32_t buff_size = lv_snapshot_buf_size_needed(obj, cf);
if(buff_size == 0) return NULL;
void * buf = lv_malloc(buff_size); void * buf = lv_malloc(buff_size);
LV_ASSERT_MALLOC(buf); LV_ASSERT_MALLOC(buf);