diff --git a/src/widgets/buttonmatrix/lv_buttonmatrix.c b/src/widgets/buttonmatrix/lv_buttonmatrix.c index 27befa32f2..06eeff5999 100644 --- a/src/widgets/buttonmatrix/lv_buttonmatrix.c +++ b/src/widgets/buttonmatrix/lv_buttonmatrix.c @@ -1036,8 +1036,8 @@ static void update_map(lv_obj_t * obj) const char * const * map_row = btnm->map_p; /*Count the units and the buttons in a line*/ - uint32_t row; - for(row = 0; row < btnm->row_cnt; row++) { + int32_t row_cnt = (int32_t)btnm->row_cnt; + for(int32_t row = 0; row < row_cnt; row++) { uint32_t unit_cnt = 0; /*Number of units in a row*/ uint32_t btn_cnt = 0; /*Number of buttons in a row*/ /*Count the buttons and units in this row*/ @@ -1052,8 +1052,8 @@ static void update_map(lv_obj_t * obj) continue; } - int32_t row_y1 = stop + (max_h_no_gap * row) / btnm->row_cnt + row * prow; - int32_t row_y2 = stop + (max_h_no_gap * (row + 1)) / btnm->row_cnt + row * prow - 1; + int32_t row_y1 = stop + (max_h_no_gap * row) / row_cnt + row * prow; + int32_t row_y2 = stop + (max_h_no_gap * (row + 1)) / row_cnt + row * prow - 1; /*Set the button size and positions*/ int32_t max_w_no_gap = max_w - (pcol * (btn_cnt - 1));