From 9eb71a0538f504131c08bf6d7d5bb1ac8fe4b393 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 27 Apr 2021 14:05:18 +0200 Subject: [PATCH] feat(btnmatrix) allow NULL terminated array too for the button's list --- src/extra/widgets/msgbox/lv_msgbox.c | 2 +- src/widgets/lv_btnmatrix.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 357eeb8fa1..f2b51c3e0a 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -89,7 +89,7 @@ lv_obj_t * lv_msgbox_create(lv_obj_t * parent, const char * title, const char * lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT); uint32_t btn_cnt = 0; - while(btn_txts[btn_cnt][0] != '\0') { + while(btn_txts[btn_cnt] && btn_txts[btn_cnt][0] != '\0') { btn_cnt++; } diff --git a/src/widgets/lv_btnmatrix.c b/src/widgets/lv_btnmatrix.c index d894782eca..03397fb30a 100644 --- a/src/widgets/lv_btnmatrix.c +++ b/src/widgets/lv_btnmatrix.c @@ -109,7 +109,7 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]) /*Count the lines to calculate button height*/ uint8_t row_cnt = 1; uint32_t i; - for(i = 0; strlen(map[i]) != 0; i++) { + for(i = 0; map[i] && map[i][0] != '\0'; i++) { if(strcmp(map[i], "\n") == 0) row_cnt++; } @@ -128,7 +128,7 @@ void lv_btnmatrix_set_map(lv_obj_t * obj, const char * map[]) uint16_t unit_cnt = 0; /*Number of units in a row*/ uint16_t btn_cnt = 0; /*Number of buttons in a row*/ /*Count the buttons and units in this row*/ - while(strcmp(map_row[btn_cnt], "\n") != 0 && strlen(map_row[btn_cnt]) != '\0') { + while(map_row[btn_cnt] && strcmp(map_row[btn_cnt], "\n") != 0 && map_row[btn_cnt][0] != '\0') { unit_cnt += get_button_width(btnm->ctrl_bits[btn_tot_i + btn_cnt]); btn_cnt++; } @@ -796,7 +796,7 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * obj, const char ** /*Count the buttons in the map*/ uint16_t btn_cnt = 0; uint16_t i = 0; - while(strlen(map[i]) != 0) { + while(map[i] && map[i][0] != '\0') { if(strcmp(map[i], "\n") != 0) { /*Do not count line breaks*/ btn_cnt++; }