From bbedf2656086a93a8468a1c98168a6b36631ce9a Mon Sep 17 00:00:00 2001 From: Akos Vandra-Meyer Date: Wed, 10 Jun 2026 11:29:26 +0200 Subject: [PATCH] feat(core): add lv_check_arg to public functions in lv_obj (#10196) Co-authored-by: Claude Sonnet 4.6 --- src/core/lv_group.c | 2 +- src/core/lv_obj.c | 30 +++++++++++++++++++----------- src/core/lv_obj_id_builtin.c | 1 + 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/core/lv_group.c b/src/core/lv_group.c index 54184120f4..02a429babb 100644 --- a/src/core/lv_group.c +++ b/src/core/lv_group.c @@ -172,7 +172,7 @@ void lv_group_swap_obj(lv_obj_t * obj1, lv_obj_t * obj2) else if((*obj_i) == obj2)(*obj_i) = obj1; } - // Swap the focus as well. + /* Swap the focus as well. */ lv_obj_t * focused = lv_group_get_focused(g1); if(focused == obj1) lv_group_focus_obj(obj2); else if(focused == obj2) lv_group_focus_obj(obj1); diff --git a/src/core/lv_obj.c b/src/core/lv_obj.c index 47298180fe..40d780a828 100644 --- a/src/core/lv_obj.c +++ b/src/core/lv_obj.c @@ -327,6 +327,7 @@ void lv_obj_remove_flag(lv_obj_t * obj, lv_obj_flag_t f) void lv_obj_set_flag(lv_obj_t * obj, lv_obj_flag_t f, bool v) { + LV_CHECK_OBJ(obj, MY_CLASS, return); if(v) lv_obj_add_flag(obj, f); else lv_obj_remove_flag(obj, f); } @@ -359,6 +360,7 @@ void lv_obj_remove_state(lv_obj_t * obj, lv_state_t state) void lv_obj_set_state(lv_obj_t * obj, lv_state_t state, bool v) { + LV_CHECK_OBJ(obj, MY_CLASS, return); if(v) lv_obj_add_state(obj, state); else lv_obj_remove_state(obj, state); } @@ -486,12 +488,14 @@ lv_obj_spec_attr_t * lv_obj_allocate_spec_attr(lv_obj_t * obj) bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p) { LV_CHECK_ARG(obj != NULL, return false); + LV_CHECK_ARG(class_p != NULL, return false); return obj->class_p == class_p; } bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p) { LV_CHECK_ARG(obj != NULL, return false); + LV_CHECK_ARG(class_p != NULL, return false); const lv_obj_class_t * obj_class = obj->class_p; while(obj_class) { @@ -504,13 +508,13 @@ bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p) const lv_obj_class_t * lv_obj_get_class(const lv_obj_t * obj) { - LV_CHECK_ARG(obj != NULL, return NULL); + LV_CHECK_ARG(obj != NULL, return NULL); /* Can't use LV_CHECK_OBJ here, it could cause an infinite recursion loop. */ return obj->class_p; } bool lv_obj_is_valid(const lv_obj_t * obj) { - LV_CHECK_ARG(obj != NULL, return false); + LV_CHECK_ARG(obj != NULL, return false); /* Can't use LV_CHECK_OBJ here, it could cause an infinite recursion loop. */ lv_display_t * disp = lv_display_get_next(NULL); while(disp) { @@ -570,6 +574,7 @@ lv_obj_t * lv_obj_find_by_id(const lv_obj_t * obj, const void * id) void lv_obj_add_screen_load_event(lv_obj_t * obj, lv_event_code_t trigger, lv_obj_t * screen, lv_screen_load_anim_t anim_type, uint32_t duration, uint32_t delay) { + LV_CHECK_OBJ(obj, MY_CLASS, return); LV_CHECK_ARG(screen != NULL, return, "can't load a non-existing screen"); LV_CHECK_ARG(duration > 0 || anim_type == LV_SCREEN_LOAD_ANIM_NONE, return); @@ -588,6 +593,8 @@ void lv_obj_add_screen_load_event(lv_obj_t * obj, lv_event_code_t trigger, lv_ob void lv_obj_add_screen_create_event(lv_obj_t * obj, lv_event_code_t trigger, lv_screen_create_cb_t screen_create_cb, lv_screen_load_anim_t anim_type, uint32_t duration, uint32_t delay) { + LV_CHECK_OBJ(obj, MY_CLASS, return); + LV_CHECK_ARG(screen_create_cb != NULL, return); LV_CHECK_ARG(duration > 0 || anim_type == LV_SCREEN_LOAD_ANIM_NONE, return); screen_load_anim_dsc_t * dsc = lv_malloc(sizeof(screen_load_anim_dsc_t)); @@ -605,7 +612,7 @@ void lv_obj_add_screen_create_event(lv_obj_t * obj, lv_event_code_t trigger, lv_ void lv_obj_add_play_timeline_event(lv_obj_t * obj, lv_event_code_t trigger, lv_anim_timeline_t * at, uint32_t delay, bool reverse) { - LV_CHECK_ARG(obj != NULL, return); + LV_CHECK_OBJ(obj, MY_CLASS, return); LV_CHECK_ARG(at != NULL, return); timeline_play_dsc_t * dsc = lv_malloc(sizeof(timeline_play_dsc_t)); @@ -621,20 +628,20 @@ void lv_obj_add_play_timeline_event(lv_obj_t * obj, lv_event_code_t trigger, lv_ void lv_obj_set_user_data(lv_obj_t * obj, void * user_data) { - LV_CHECK_ARG(obj != NULL, return); + LV_CHECK_OBJ(obj, MY_CLASS, return); obj->user_data = user_data; } void * lv_obj_get_user_data(lv_obj_t * obj) { - LV_CHECK_ARG(obj != NULL, return NULL); + LV_CHECK_OBJ(obj, MY_CLASS, return NULL); return obj->user_data; } lv_delete_dsc_t * lv_obj_add_delete_cb(lv_obj_t * obj, lv_delete_cb_t cb, void * user_data) { - LV_CHECK_ARG(obj != NULL, return NULL); + LV_CHECK_OBJ(obj, MY_CLASS, return NULL); LV_CHECK_ARG(cb != NULL, return NULL); lv_delete_dsc_t * dsc = lv_malloc(sizeof(*dsc)); @@ -673,7 +680,7 @@ void lv_obj_remove_delete_cb(lv_delete_dsc_t * dsc) static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { - LV_CHECK_ARG(obj != NULL, return); + LV_ASSERT(obj != NULL); LV_UNUSED(class_p); LV_TRACE_OBJ_CREATE("begin"); @@ -710,7 +717,7 @@ static void lv_obj_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) static void lv_obj_destructor(const lv_obj_class_t * class_p, lv_obj_t * obj) { - LV_CHECK_ARG(obj != NULL, return); + LV_ASSERT(obj != NULL); LV_UNUSED(class_p); @@ -1184,9 +1191,10 @@ static void lv_obj_event(const lv_obj_class_t * class_p, lv_event_t * e) */ static void update_obj_state(lv_obj_t * obj, lv_state_t new_state) { + LV_ASSERT(obj != NULL); + if(obj->state == new_state) return; - LV_CHECK_OBJ(obj, MY_CLASS, return); lv_state_t prev_state = obj->state; @@ -1414,7 +1422,7 @@ static lv_point_t lv_obj_get_scroll_end_helper(lv_obj_t * obj) static lv_result_t lv_obj_set_any(lv_obj_t * obj, lv_prop_id_t id, const lv_property_t * prop) { - LV_CHECK_OBJ(obj, MY_CLASS, return LV_RESULT_INVALID); + LV_ASSERT(obj != NULL); if(id >= LV_PROPERTY_OBJ_FLAG_START && id <= LV_PROPERTY_OBJ_FLAG_END) { lv_obj_flag_t flag = 1L << (id - LV_PROPERTY_OBJ_FLAG_START); @@ -1439,7 +1447,7 @@ static lv_result_t lv_obj_set_any(lv_obj_t * obj, lv_prop_id_t id, const lv_prop static lv_result_t lv_obj_get_any(const lv_obj_t * obj, lv_prop_id_t id, lv_property_t * prop) { - LV_CHECK_OBJ(obj, MY_CLASS, return LV_RESULT_INVALID); + LV_ASSERT(obj != NULL); if(id >= LV_PROPERTY_OBJ_FLAG_START && id <= LV_PROPERTY_OBJ_FLAG_END) { lv_obj_flag_t flag = 1L << (id - LV_PROPERTY_OBJ_FLAG_START); prop->id = id; diff --git a/src/core/lv_obj_id_builtin.c b/src/core/lv_obj_id_builtin.c index f1302f99d0..d0e86e8009 100644 --- a/src/core/lv_obj_id_builtin.c +++ b/src/core/lv_obj_id_builtin.c @@ -97,6 +97,7 @@ const char * lv_obj_stringify_id(lv_obj_t * obj, char * buf, uint32_t len) LV_CHECK_ARG(obj != NULL, return NULL); LV_CHECK_ARG(obj->class_p != NULL, return NULL); LV_CHECK_ARG(buf != NULL, return NULL); + LV_CHECK_ARG(len > 0, return NULL); const char * name = obj->class_p->name; if(name == NULL) name = "nameless";