feat(style): add style_cnt and styles checks (#6873)

This commit is contained in:
glory-man
2024-09-26 11:53:46 +03:00
committed by GitHub
parent 03e01bdd3e
commit 7a3322a487

View File

@@ -75,8 +75,13 @@ void _lv_obj_style_init(void)
void lv_obj_add_style(lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector) void lv_obj_add_style(lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector)
{ {
LV_ASSERT(obj->style_cnt < 63);
trans_del(obj, selector, LV_STYLE_PROP_ANY, NULL); trans_del(obj, selector, LV_STYLE_PROP_ANY, NULL);
/*Try removing the style first to be sure it won't be added twice*/
lv_obj_remove_style(obj, style, selector);
uint32_t i; uint32_t i;
/*Go after the transition and local styles*/ /*Go after the transition and local styles*/
for(i = 0; i < obj->style_cnt; i++) { for(i = 0; i < obj->style_cnt; i++) {
@@ -89,7 +94,9 @@ void lv_obj_add_style(lv_obj_t * obj, lv_style_t * style, lv_style_selector_t se
/*Allocate space for the new style and shift the rest of the style to the end*/ /*Allocate space for the new style and shift the rest of the style to the end*/
obj->style_cnt++; obj->style_cnt++;
LV_ASSERT(obj->style_cnt != 0);
obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t)); obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t));
LV_ASSERT_MALLOC(obj->styles);
uint32_t j; uint32_t j;
for(j = obj->style_cnt - 1; j > i ; j--) { for(j = obj->style_cnt - 1; j > i ; j--) {
@@ -548,6 +555,7 @@ static lv_style_t * get_local_style(lv_obj_t * obj, lv_style_selector_t selector
} }
obj->style_cnt++; obj->style_cnt++;
LV_ASSERT(obj->style_cnt != 0);
obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t)); obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t));
LV_ASSERT_MALLOC(obj->styles); LV_ASSERT_MALLOC(obj->styles);
@@ -584,7 +592,9 @@ static _lv_obj_style_t * get_trans_style(lv_obj_t * obj, lv_style_selector_t se
if(i != obj->style_cnt) return &obj->styles[i]; if(i != obj->style_cnt) return &obj->styles[i];
obj->style_cnt++; obj->style_cnt++;
LV_ASSERT(obj->style_cnt != 0);
obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t)); obj->styles = lv_mem_realloc(obj->styles, obj->style_cnt * sizeof(_lv_obj_style_t));
LV_ASSERT_MALLOC(obj->styles);
for(i = obj->style_cnt - 1; i > 0 ; i--) { for(i = obj->style_cnt - 1; i > 0 ; i--) {
obj->styles[i] = obj->styles[i - 1]; obj->styles[i] = obj->styles[i - 1];