From c4cab173c965196b2263c165618272c053658c96 Mon Sep 17 00:00:00 2001 From: linyiyang <50727129+eYoung8475@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:49:37 +0800 Subject: [PATCH] fix(dropdown): avoid partial match in lv_dropdown_get_option_index (#4598) --- src/widgets/dropdown/lv_dropdown.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/widgets/dropdown/lv_dropdown.c b/src/widgets/dropdown/lv_dropdown.c index 0c3b330f0..6dd59911e 100644 --- a/src/widgets/dropdown/lv_dropdown.c +++ b/src/widgets/dropdown/lv_dropdown.c @@ -413,8 +413,10 @@ int32_t lv_dropdown_get_option_index(lv_obj_t * obj, const char * option) while(start[0] != '\0') { for(char_i = 0; (start[char_i] != '\n') && (start[char_i] != '\0'); char_i++); - if(option_len == char_i && - memcmp(start, option, option_len) == 0) return opt_i; /*cannot match exactly unless they are the same length*/ + if(option_len == char_i && memcmp(start, option, LV_MIN(option_len, char_i)) == 0) { + return opt_i; + } + start = &start[char_i]; if(start[0] == '\n') start++; char_i = 0;