diff --git a/docs/changes.md b/docs/changes.md index 797d71eba..2571f00a7 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,8 @@ # 最新动态 +2022/11/21 + * 完善widget_lookup接口,避免访问空指针导致程序崩溃(感谢雨欣提供补丁) + 2022/11/20 * 增加lcd_mem的测试用例题(感谢智明提供补丁) diff --git a/src/base/widget.c b/src/base/widget.c index e7ea52f5c..d406595fd 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -1184,7 +1184,7 @@ static widget_t* widget_lookup_child(widget_t* widget, const char* name) { return_value_if_fail(widget != NULL && name != NULL, NULL); WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i) - if (iter->name != NULL && tk_str_eq(iter->name, name)) { + if (iter != NULL && iter->name != NULL && tk_str_eq(iter->name, name)) { return iter; } WIDGET_FOR_EACH_CHILD_END() @@ -1219,7 +1219,7 @@ static widget_t* widget_lookup_all(widget_t* widget, const char* name) { return_value_if_fail(widget != NULL && name != NULL, NULL); WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i) - if (iter->name != NULL && tk_str_eq(iter->name, name)) { + if (iter != NULL && iter->name != NULL && tk_str_eq(iter->name, name)) { return iter; } else { iter = widget_lookup_all(iter, name);