From 3e8a8887a5772926883af457fe251a108cef15e7 Mon Sep 17 00:00:00 2001 From: C47D Date: Wed, 17 Jan 2024 14:07:49 -0600 Subject: [PATCH] test(obj_tree): Add assertions in get_index and move_to_index --- src/core/lv_obj_tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/lv_obj_tree.c b/src/core/lv_obj_tree.c index e3040730d995..aaa2d7d42d69 100644 --- a/src/core/lv_obj_tree.c +++ b/src/core/lv_obj_tree.c @@ -210,7 +210,9 @@ void lv_obj_move_to_index(lv_obj_t * obj, int32_t index) } const uint32_t parent_child_count = lv_obj_get_child_count(parent); + /* old_index only can be 0 or greater, this point can not be reached if the parent is null */ const int32_t old_index = lv_obj_get_index(obj); + LV_ASSERT(0 <= old_index); if(index < 0) { index += parent_child_count; @@ -416,14 +418,16 @@ int32_t lv_obj_get_index(const lv_obj_t * obj) LV_ASSERT_OBJ(obj, MY_CLASS); lv_obj_t * parent = lv_obj_get_parent(obj); - if(parent == NULL) return 0xFFFFFFFF; + if(parent == NULL) return -1; int32_t i = 0; for(i = 0; i < parent->spec_attr->child_cnt; i++) { if(parent->spec_attr->children[i] == obj) return i; } - return -1; /*Shouldn't happen*/ + /*Shouldn't reach this point*/ + LV_ASSERT(0); + return -1; } int32_t lv_obj_get_index_by_type(const lv_obj_t * obj, const lv_obj_class_t * class_p)