From 7c583ac8d6f6c9a449556baa819cd4e63b34d67b Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Wed, 15 Feb 2023 20:57:41 +0100 Subject: [PATCH] fix(img): possible divide by 0 exception (lvgl#3988) (#3991) Co-authored-by: fvanroie --- src/widgets/img/lv_img.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/widgets/img/lv_img.c b/src/widgets/img/lv_img.c index 0eb839910..463bd455f 100644 --- a/src/widgets/img/lv_img.c +++ b/src/widgets/img/lv_img.c @@ -166,8 +166,6 @@ void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x) lv_img_t * img = (lv_img_t *)obj; - x = x % img->w; - img->offset.x = x; lv_obj_invalidate(obj); } @@ -178,8 +176,6 @@ void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y) lv_img_t * img = (lv_img_t *)obj; - y = y % img->h; - img->offset.y = y; lv_obj_invalidate(obj); } @@ -660,12 +656,14 @@ static void draw_img(lv_event_t * e) draw_ctx->clip_area = &img_clip_area; lv_area_t coords_tmp; - coords_tmp.y1 = img_max_area.y1 + img->offset.y; + lv_coord_t offset_x = img->offset.x % img->w; + lv_coord_t offset_y = img->offset.y % img->h; + coords_tmp.y1 = img_max_area.y1 + offset_y; if(coords_tmp.y1 > img_max_area.y1) coords_tmp.y1 -= img->h; coords_tmp.y2 = coords_tmp.y1 + img->h - 1; for(; coords_tmp.y1 < img_max_area.y2; coords_tmp.y1 += img_size_final.y, coords_tmp.y2 += img_size_final.y) { - coords_tmp.x1 = img_max_area.x1 + img->offset.x; + coords_tmp.x1 = img_max_area.x1 + offset_x; if(coords_tmp.x1 > img_max_area.x1) coords_tmp.x1 -= img->w; coords_tmp.x2 = coords_tmp.x1 + img->w - 1;