diff --git a/docs/changes.md b/docs/changes.md index 6aaefe9ac..79b558502 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -6,6 +6,7 @@ * 修复卸载资源管理器不正常的问题(感谢智明提供补丁) * 在mingw下盘符路径不正常的问题(感谢智明提供补丁) * 修复命令行使用mwindow不正常的问题(感谢智明提供补丁) + * 修正cppcheck和infer静态检查警告(感谢陈谭提供补丁) 2023/09/15 * 修复 path\_basename\_ex 的对于混合斜杆不支持的问题(感谢智明提供补丁) diff --git a/src/base/canvas.c b/src/base/canvas.c index a3bc8744c..8df2b82e7 100644 --- a/src/base/canvas.c +++ b/src/base/canvas.c @@ -326,7 +326,7 @@ ret_t canvas_set_text_align(canvas_t* c, align_h_t align_h, align_v_t align_v) { } static float_t canvas_measure_text_default(canvas_t* c, const wchar_t* str, uint32_t nr) { - glyph_t g; + glyph_t g = {0}; float_t w = 0; uint32_t i = 0; return_value_if_fail(c != NULL && str != NULL && c->font != NULL, 0); diff --git a/src/base/image_base.c b/src/base/image_base.c index 9ef066cbd..27efbee30 100644 --- a/src/base/image_base.c +++ b/src/base/image_base.c @@ -175,6 +175,7 @@ widget_t* image_base_init(widget_t* widget) { ret_t image_base_set_image(widget_t* widget, const char* name) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL && name != NULL, RET_BAD_PARAMS); if (!tk_str_eq(image->image, name)) { @@ -187,6 +188,7 @@ ret_t image_base_set_image(widget_t* widget, const char* name) { ret_t image_base_set_rotation(widget_t* widget, float_t rotation) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->rotation = rotation; @@ -196,6 +198,7 @@ ret_t image_base_set_rotation(widget_t* widget, float_t rotation) { ret_t image_base_set_scale(widget_t* widget, float_t scale_x, float_t scale_y) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->scale_x = scale_x; @@ -206,6 +209,7 @@ ret_t image_base_set_scale(widget_t* widget, float_t scale_x, float_t scale_y) { ret_t image_base_set_anchor(widget_t* widget, float_t anchor_x, float_t anchor_y) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->anchor_x = anchor_x; @@ -216,6 +220,7 @@ ret_t image_base_set_anchor(widget_t* widget, float_t anchor_x, float_t anchor_y ret_t image_base_set_selected(widget_t* widget, bool_t selected) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->selected = selected; @@ -231,6 +236,7 @@ ret_t image_base_set_selected(widget_t* widget, bool_t selected) { ret_t image_base_set_selectable(widget_t* widget, bool_t selectable) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->selectable = selectable; @@ -240,6 +246,7 @@ ret_t image_base_set_selectable(widget_t* widget, bool_t selectable) { ret_t image_base_set_clickable(widget_t* widget, bool_t clickable) { image_base_t* image = IMAGE_BASE(widget); + ENSURE(image); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); image->clickable = clickable; @@ -258,6 +265,7 @@ widget_t* image_base_cast(widget_t* widget) { bool_t image_need_transform(widget_t* widget) { image_base_t* image_base = IMAGE_BASE(widget); + ENSURE(image_base); return_value_if_fail(widget != NULL, FALSE); return !tk_fequal(image_base->scale_x, 1) || !tk_fequal(image_base->scale_y, 1) || @@ -268,6 +276,7 @@ ret_t image_transform(widget_t* widget, canvas_t* c) { float_t anchor_x = 0; float_t anchor_y = 0; image_base_t* image_base = IMAGE_BASE(widget); + ENSURE(image_base); vgcanvas_t* vg = canvas_get_vgcanvas(c); return_value_if_fail(widget != NULL && vg != NULL, RET_BAD_PARAMS); diff --git a/src/base/widget.c b/src/base/widget.c index 43d33c3e5..1480b8de5 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -2025,6 +2025,7 @@ static ret_t fscript_info_prepare(fscript_info_t* info, event_t* evt) { case EVT_POINTER_MOVE: case EVT_POINTER_UP: { pointer_event_t* e = pointer_event_cast(evt); + ENSURE(e); tk_object_set_prop_int(obj, "x", e->x); tk_object_set_prop_int(obj, "y", e->y); tk_object_set_prop_bool(obj, "alt", e->alt); @@ -2037,6 +2038,7 @@ static ret_t fscript_info_prepare(fscript_info_t* info, event_t* evt) { case EVT_KEY_LONG_PRESS: case EVT_KEY_UP: { key_event_t* e = key_event_cast(evt); + ENSURE(e); const key_type_value_t* kv = keys_type_find_by_value(e->key); if (kv != NULL) { tk_object_set_prop_str(obj, "key", kv->name); @@ -2051,6 +2053,7 @@ static ret_t fscript_info_prepare(fscript_info_t* info, event_t* evt) { } case EVT_MODEL_CHANGE: { model_event_t* e = model_event_cast(evt); + ENSURE(e); tk_object_set_prop_str(obj, "name", e->name); tk_object_set_prop_str(obj, "change_type", e->change_type); tk_object_set_prop_object(obj, "model", e->model); diff --git a/src/base/window_base.c b/src/base/window_base.c index c07d1e3ab..e4b12a811 100644 --- a/src/base/window_base.c +++ b/src/base/window_base.c @@ -60,6 +60,7 @@ ret_t window_base_on_paint_end(widget_t* widget, canvas_t* c) { static ret_t window_base_unload_default_theme_obj_impl(widget_t* widget) { window_base_t* window_base = WINDOW_BASE(widget); + ENSURE(window_base); assets_manager_t* am = widget_get_assets_manager(widget); if (window_base->default_res_theme != NULL) { @@ -77,6 +78,7 @@ static ret_t window_base_unload_default_theme_obj_impl(widget_t* widget) { static ret_t window_base_unload_theme_obj_impl(widget_t* widget) { window_base_t* window_base = WINDOW_BASE(widget); + ENSURE(window_base); assets_manager_t* am = widget_get_assets_manager(widget); if (window_base->res_theme != NULL) { @@ -100,6 +102,7 @@ static ret_t window_base_unload_theme_obj(widget_t* widget) { static ret_t window_base_load_default_theme_obj_impl(widget_t* widget, bool_t* update_style) { window_base_t* window_base = WINDOW_BASE(widget); + ENSURE(window_base); assets_manager_t* am = widget_get_assets_manager(widget); if (window_base->default_theme_obj != NULL) { @@ -126,6 +129,7 @@ static ret_t window_base_load_default_theme_obj_impl(widget_t* widget, bool_t* u static ret_t window_base_load_theme_obj_impl(widget_t* widget, bool_t* update_style) { const char* theme_name = widget->name; window_base_t* window_base = WINDOW_BASE(widget); + ENSURE(window_base); assets_manager_t* am = widget_get_assets_manager(widget); if (window_base->theme_obj != NULL) { @@ -301,6 +305,7 @@ ret_t window_base_get_prop(widget_t* widget, const char* name, value_t* v) { static ret_t window_base_set_applet_name(widget_t* widget, const char* applet_name) { window_base_t* window_base = WINDOW_BASE(widget); + ENSURE(window_base); if (tk_str_eq(window_base->applet_name, applet_name)) { return RET_OK; } @@ -478,6 +483,7 @@ static widget_t* window_base_get_key_target_leaf(widget_t* widget) { ret_t window_base_auto_scale_children(widget_t* widget) { window_base_t* win = WINDOW_BASE(widget); + ENSURE(win); return_value_if_fail(win->design_w > 0 && win->design_h > 0, RET_BAD_PARAMS); return widget_auto_scale_children(widget, win->design_w, win->design_h, @@ -600,7 +606,9 @@ ret_t window_base_on_event(widget_t* widget, event_t* e) { static ret_t window_on_keydown_before_children(void* ctx, event_t* e) { widget_t* win = WIDGET(ctx); key_event_t* evt = key_event_cast(e); + ENSURE(evt); window_base_t* base = WINDOW_BASE(win); + ENSURE(base); widget_t* focus = widget_get_focused_widget(win); keyboard_type_t keyboard_type = system_info()->keyboard_type; diff --git a/src/conf_io/conf_obj.c b/src/conf_io/conf_obj.c index b325d4294..ac292f351 100644 --- a/src/conf_io/conf_obj.c +++ b/src/conf_io/conf_obj.c @@ -448,6 +448,7 @@ static ret_t conf_sub_obj_foreach(tk_object_t* obj, tk_visit_t on_prop, void* ct static ret_t conf_sub_obj_destroy(tk_object_t* obj) { conf_sub_obj_t* o = CONF_SUB_OBJ(obj); + ENSURE(o); TK_OBJECT_UNREF(o->conf); o->root = NULL; o->real_root = NULL; @@ -488,6 +489,7 @@ tk_object_t* conf_sub_obj_create(tk_object_t* conf, const char* path) { return_value_if_fail(root != NULL, NULL); } else { conf_obj = CONF_OBJ(conf); + ENSURE(conf_obj); root = conf_doc_find_node(conf_obj->doc, conf_obj->doc->root, path, FALSE); return_value_if_fail(root != NULL, NULL); } diff --git a/src/conf_io/conf_xml.c b/src/conf_io/conf_xml.c index 61640f487..1c4f929ad 100644 --- a/src/conf_io/conf_xml.c +++ b/src/conf_io/conf_xml.c @@ -175,6 +175,7 @@ static ret_t conf_doc_save_xml_node(conf_doc_t* doc, str_t* str, conf_node_t* no uint32_t level) { uint32_t size = 0; const char* name = conf_node_get_name(node); + ENSURE(name); conf_node_t* text = NULL; conf_node_t* iter = conf_node_get_first_child(node); diff --git a/src/dialog_highlighters/dialog_highlighter_default.c b/src/dialog_highlighters/dialog_highlighter_default.c index d1b5d1a7a..82700c6e6 100644 --- a/src/dialog_highlighters/dialog_highlighter_default.c +++ b/src/dialog_highlighters/dialog_highlighter_default.c @@ -290,6 +290,7 @@ static ret_t dialog_highlighter_default_system_bar_top_append_clip_rect(dialog_h dialog_highlighter_default_t* dh = (dialog_highlighter_default_t*)h; if (rect->w != 0 && rect->h != 0) { rect_t* r = TKMEM_ZALLOC(rect_t); + ENSURE(r); memcpy(r, rect, sizeof(rect_t)); ret = darray_push(&dh->system_bar_top_clip_rects, r); } @@ -301,6 +302,7 @@ static ret_t dialog_highlighter_default_system_bar_bottom_append_clip_rect(dialo dialog_highlighter_default_t* dh = (dialog_highlighter_default_t*)h; if (rect->w != 0 && rect->h != 0) { rect_t* r = TKMEM_ZALLOC(rect_t); + ENSURE(r); memcpy(r, rect, sizeof(rect_t)); ret = darray_push(&dh->system_bar_bottom_clip_rects, r); } diff --git a/src/ext_widgets/combo_box_ex/combo_box_ex.c b/src/ext_widgets/combo_box_ex/combo_box_ex.c index 2d535c39f..4e95d6181 100644 --- a/src/ext_widgets/combo_box_ex/combo_box_ex.c +++ b/src/ext_widgets/combo_box_ex/combo_box_ex.c @@ -55,6 +55,7 @@ static ret_t combo_box_ex_create_popup_items(combo_box_t* combo_box, widget_t* p widget_set_value(item, iter->value); } + ENSURE(item); if (combo_box->localize_options) { widget_set_tr_text(item, text); } else { diff --git a/src/ext_widgets/gauge/gauge_pointer.c b/src/ext_widgets/gauge/gauge_pointer.c index 1fefcd10b..47f133397 100644 --- a/src/ext_widgets/gauge/gauge_pointer.c +++ b/src/ext_widgets/gauge/gauge_pointer.c @@ -44,6 +44,7 @@ static rect_t gauge_pointer_calc_dirty_rect(widget_t* widget, int32_t img_w, int int32_t ox = widget->x; int32_t oy = widget->y; gauge_pointer_t* gauge_pointer = GAUGE_POINTER(widget); + ENSURE(gauge_pointer); float_t rotation = TK_D2R(gauge_pointer->angle); float_t anchor_x = tk_eval_ratio_or_px(gauge_pointer->anchor_x, widget->w); float_t anchor_y = tk_eval_ratio_or_px(gauge_pointer->anchor_y, widget->h); @@ -135,6 +136,7 @@ static ret_t gauge_pointer_invalidate(widget_t* widget, const rect_t* rect) { ret_t gauge_pointer_set_angle(widget_t* widget, float_t angle) { gauge_pointer_t* gauge_pointer = GAUGE_POINTER(widget); + ENSURE(gauge_pointer); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); if (gauge_pointer->angle != angle) { @@ -225,6 +227,7 @@ ret_t gauge_pointer_set_image(widget_t* widget, const char* image) { static ret_t gauge_pointer_get_prop(widget_t* widget, const char* name, value_t* v) { gauge_pointer_t* gauge_pointer = GAUGE_POINTER(widget); + ENSURE(gauge_pointer); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, GAUGE_POINTER_PROP_ANGLE) || tk_str_eq(name, WIDGET_PROP_VALUE)) { diff --git a/src/ext_widgets/mledit/line_number.c b/src/ext_widgets/mledit/line_number.c index 5d963d5e3..3f1888056 100644 --- a/src/ext_widgets/mledit/line_number.c +++ b/src/ext_widgets/mledit/line_number.c @@ -46,6 +46,7 @@ static ret_t line_number_do_paint_self(widget_t* widget, canvas_t* c) { uint32_t w = widget->w - 2 * x; rect_t r = rect_init(0, 0, 0, 0); line_number_t* line_number = LINE_NUMBER(widget); + ENSURE(line_number); int32_t yoffset = line_number->yoffset; int32_t line_height = line_number->line_height; style_t* style = widget->astyle; diff --git a/src/ext_widgets/mledit/mledit.c b/src/ext_widgets/mledit/mledit.c index 79aa98cdc..352b58caa 100644 --- a/src/ext_widgets/mledit/mledit.c +++ b/src/ext_widgets/mledit/mledit.c @@ -341,6 +341,7 @@ static ret_t mledit_set_text(widget_t* widget, const value_t* v) { wstr_t str; wstr_init(&str, 0); mledit_t* mledit = MLEDIT(widget); + ENSURE(mledit); return_value_if_fail(wstr_from_value(&str, v) == RET_OK, RET_BAD_PARAMS); if (!wstr_equal(&(widget->text), &str)) { @@ -774,6 +775,7 @@ static ret_t mledit_on_event(widget_t* widget, event_t* e) { } case EVT_KEY_UP: { key_event_t* evt = key_event_cast(e); + ENSURE(evt); int32_t key = evt->key; if (key == TK_KEY_ESCAPE || (key >= TK_KEY_F1 && key <= TK_KEY_F12)) { @@ -978,6 +980,7 @@ static ret_t mledit_on_text_edit_state_changed(void* ctx, text_edit_state_t* sta static ret_t mledit_on_scroll_bar_value_changed(void* ctx, event_t* e) { int32_t value = 0; mledit_t* mledit = MLEDIT(ctx); + ENSURE(mledit); widget_t* vscroll_bar = e != NULL ? WIDGET(e->target) : NULL; scroll_bar_t* scroll_bar = SCROLL_BAR(vscroll_bar); diff --git a/src/ext_widgets/mutable_image/mutable_image.c b/src/ext_widgets/mutable_image/mutable_image.c index e09638434..a15abd626 100644 --- a/src/ext_widgets/mutable_image/mutable_image.c +++ b/src/ext_widgets/mutable_image/mutable_image.c @@ -69,6 +69,7 @@ static bitmap_t* mutable_image_prepare_image(widget_t* widget, canvas_t* c) { ret_t mutable_image_on_paint_self(widget_t* widget, canvas_t* canvas) { mutable_image_t* mutable_image = MUTABLE_IMAGE(widget); + ENSURE(mutable_image); bitmap_t* bitmap = mutable_image->user_image != NULL ? mutable_image->user_image : mutable_image_prepare_image(widget, canvas); @@ -135,6 +136,7 @@ ret_t mutable_image_on_attach_parent(widget_t* widget, widget_t* parent) { static ret_t mutable_image_set_prop(widget_t* widget, const char* name, const value_t* v) { mutable_image_t* mutable_image = MUTABLE_IMAGE(widget); + ENSURE(mutable_image); if (tk_str_eq(name, WIDGET_PROP_IMAGE) || tk_str_eq(name, WIDGET_PROP_VALUE)) { mutable_image->user_image = (bitmap_t*)value_bitmap(v); if (mutable_image->user_image != NULL && mutable_image->image != NULL) { @@ -162,6 +164,7 @@ TK_DECL_VTABLE(mutable_image) = {.size = sizeof(mutable_image_t), static ret_t mutable_image_invalidate(const timer_info_t* info) { widget_t* widget = WIDGET(info->ctx); mutable_image_t* mutable_image = MUTABLE_IMAGE(widget); + ENSURE(mutable_image); if (mutable_image->need_redraw == NULL || mutable_image->need_redraw(mutable_image->need_redraw_ctx)) { diff --git a/src/ext_widgets/progress_circle/progress_circle.c b/src/ext_widgets/progress_circle/progress_circle.c index 5edce2d11..479bffece 100644 --- a/src/ext_widgets/progress_circle/progress_circle.c +++ b/src/ext_widgets/progress_circle/progress_circle.c @@ -84,6 +84,7 @@ static ret_t progress_circle_update_text(widget_t* widget) { static float_t progress_circle_value_to_angle(widget_t* widget, float_t value) { float_t end_angle = 0; progress_circle_t* progress_circle = PROGRESS_CIRCLE(widget); + ENSURE(progress_circle); bool_t ccw = progress_circle->counter_clock_wise; float_t start_angle = TK_D2R(progress_circle->start_angle); float_t angle = (M_PI * 2 * value) / progress_circle->max; @@ -104,6 +105,7 @@ static float_t progress_circle_get_radius(widget_t* widget) { xy_t cx = widget->w / 2; xy_t cy = widget->h / 2; progress_circle_t* progress_circle = PROGRESS_CIRCLE(widget); + ENSURE(progress_circle); return tk_min(cx, cy) - progress_circle->line_width / 2; } @@ -112,6 +114,7 @@ rect_t progress_circle_calc_text_dirty_rect(widget_t* widget) { rect_t r = {0, 0, 0, 0}; canvas_t* c = widget_get_canvas(widget); progress_circle_t* progress_circle = PROGRESS_CIRCLE(widget); + ENSURE(progress_circle); if (widget->w < 1 || widget->h < 1) { return r; @@ -144,6 +147,7 @@ rect_t progress_circle_calc_line_dirty_rect(widget_t* widget, float_t old_value, point_t start_p = {0, 0}; point_t end_p = {0, 0}; progress_circle_t* progress_circle = PROGRESS_CIRCLE(widget); + ENSURE(progress_circle); float_t line_width = progress_circle->line_width; start_angle = progress_circle_value_to_angle(widget, old_value); diff --git a/src/ext_widgets/rich_text/rich_text.c b/src/ext_widgets/rich_text/rich_text.c index 5aaac9d75..2507cc7be 100644 --- a/src/ext_widgets/rich_text/rich_text.c +++ b/src/ext_widgets/rich_text/rich_text.c @@ -54,6 +54,7 @@ static ret_t rich_text_get_margin(widget_t* widget) { int32_t margin = 0; int32_t tmp_margin = 0; rich_text_t* rich_text = RICH_TEXT(widget); + ENSURE(rich_text); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); margin = style_get_int(widget->astyle, STYLE_ID_MARGIN, 0); tmp_margin = rich_text->margin; diff --git a/src/ext_widgets/scroll_label/hscroll_label.c b/src/ext_widgets/scroll_label/hscroll_label.c index fb05e052d..94d7e6db1 100644 --- a/src/ext_widgets/scroll_label/hscroll_label.c +++ b/src/ext_widgets/scroll_label/hscroll_label.c @@ -45,6 +45,7 @@ static ret_t hscroll_label_do_paint_self(widget_t* widget, canvas_t* c, uint32_t wstr_t* text = &(widget->text); uint32_t w = widget->w - left_margin - right_margin; hscroll_label_t* hscroll_label = HSCROLL_LABEL(widget); + ENSURE(hscroll_label); hscroll_label->text_w = canvas_measure_text(c, text->str, text->size); if (hscroll_label->text_w != hscroll_label->old_text_w) { @@ -237,6 +238,7 @@ static ret_t hscroll_label_get_prop(widget_t* widget, const char* name, value_t* static ret_t hscroll_label_set_prop(widget_t* widget, const char* name, const value_t* v) { hscroll_label_t* hscroll_label = HSCROLL_LABEL(widget); + ENSURE(hscroll_label); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, HSCROLL_LABEL_PROP_LOOP)) { @@ -271,6 +273,7 @@ static ret_t hscroll_label_set_prop(widget_t* widget, const char* name, const va static int32_t hscroll_label_get_range(widget_t* widget) { hscroll_label_t* hscroll_label = HSCROLL_LABEL(widget); + ENSURE(hscroll_label); int32_t left_margin = style_get_int(widget->astyle, STYLE_ID_MARGIN_LEFT, 2); int32_t right_margin = style_get_int(widget->astyle, STYLE_ID_MARGIN_RIGHT, 2); int32_t w = widget->w - left_margin - right_margin; @@ -281,6 +284,7 @@ static int32_t hscroll_label_get_range(widget_t* widget) { ret_t hscroll_label_step(widget_t* widget) { ret_t ret = RET_REPEAT; hscroll_label_t* hscroll_label = HSCROLL_LABEL(widget); + ENSURE(hscroll_label); float_t percent = 0; uint32_t duration = 0; int32_t range = hscroll_label_get_range(widget); diff --git a/src/ext_widgets/scroll_view/list_view_h.c b/src/ext_widgets/scroll_view/list_view_h.c index f10970505..bfdaa149e 100644 --- a/src/ext_widgets/scroll_view/list_view_h.c +++ b/src/ext_widgets/scroll_view/list_view_h.c @@ -33,6 +33,7 @@ static ret_t list_view_h_on_paint_self(widget_t* widget, canvas_t* c) { static ret_t list_view_h_get_prop(widget_t* widget, const char* name, value_t* v) { list_view_h_t* list_view_h = LIST_VIEW_H(widget); + ENSURE(list_view_h); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_ITEM_WIDTH)) { @@ -48,6 +49,7 @@ static ret_t list_view_h_get_prop(widget_t* widget, const char* name, value_t* v static ret_t list_view_h_set_prop(widget_t* widget, const char* name, const value_t* v) { list_view_h_t* list_view_h = LIST_VIEW_H(widget); + ENSURE(list_view_h); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_ITEM_WIDTH)) { @@ -151,6 +153,7 @@ static ret_t list_view_h_on_scroll_view_layout_children(widget_t* widget) { static ret_t list_view_h_on_add_child(widget_t* widget, widget_t* child) { list_view_h_t* list_view_h = LIST_VIEW_H(widget); + ENSURE(list_view_h); const char* type = widget_get_type(child); if (tk_str_eq(type, WIDGET_TYPE_SCROLL_VIEW)) { @@ -169,6 +172,7 @@ widget_t* list_view_h_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) { ret_t list_view_h_set_item_width(widget_t* widget, int32_t item_width) { list_view_h_t* list_view_h = LIST_VIEW_H(widget); + ENSURE(list_view_h); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); list_view_h->item_width = item_width; @@ -178,6 +182,7 @@ ret_t list_view_h_set_item_width(widget_t* widget, int32_t item_width) { ret_t list_view_h_set_spacing(widget_t* widget, int32_t spacing) { list_view_h_t* list_view_h = LIST_VIEW_H(widget); + ENSURE(list_view_h); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); list_view_h->spacing = spacing; diff --git a/src/ext_widgets/scroll_view/scroll_bar.c b/src/ext_widgets/scroll_view/scroll_bar.c index fb42d5795..bca8d7157 100644 --- a/src/ext_widgets/scroll_view/scroll_bar.c +++ b/src/ext_widgets/scroll_view/scroll_bar.c @@ -61,6 +61,7 @@ static ret_t scroll_bar_mobile_get_dragger_size(widget_t* widget, rect_t* r) { int64_t widget_w = widget->w; int64_t widget_h = widget->h; scroll_bar_t* scroll_bar = SCROLL_BAR(widget); + ENSURE(scroll_bar); if (scroll_bar->virtual_size <= 0) { return RET_OK; @@ -118,6 +119,7 @@ static ret_t scroll_bar_desktop_on_click(widget_t* widget, pointer_event_t* e) { int32_t delta = 0; point_t p = {e->x, e->y}; scroll_bar_t* scroll_bar = SCROLL_BAR(widget); + ENSURE(scroll_bar); if (widget->target != NULL) { return RET_OK; @@ -261,6 +263,7 @@ ret_t scroll_bar_add_delta_ex(widget_t* widget, int32_t d, bool_t animatable) { int64_t delta = 0; int64_t new_value = 0; scroll_bar_t* scroll_bar = SCROLL_BAR(widget); + ENSURE(scroll_bar); if (widget->w > widget->h) { if (scroll_bar->virtual_size > widget->w) { @@ -312,6 +315,7 @@ static ret_t scroll_bar_on_drag(void* ctx, event_t* e) { int64_t widget_w = widget->w; int64_t widget_h = widget->h; scroll_bar_t* scroll_bar = SCROLL_BAR(ctx); + ENSURE(scroll_bar); widget_t* dragger = scroll_bar->dragger; widget_t* up = widget_lookup(widget, CHILD_UP, FALSE); widget_t* down = widget_lookup(widget, CHILD_DOWN, FALSE); @@ -367,6 +371,7 @@ static ret_t scroll_bar_on_layout_children(widget_t* widget) { int32_t widget_h = widget->h; rect_t r = rect_init(0, 0, 0, 0); scroll_bar_t* scroll_bar = SCROLL_BAR(widget); + ENSURE(scroll_bar); widget_t* dragger = scroll_bar->dragger; widget_t* up = widget_lookup(widget, CHILD_UP, FALSE); widget_t* down = widget_lookup(widget, CHILD_DOWN, FALSE); @@ -688,7 +693,7 @@ static ret_t scroll_bar_set_value_only_impl(widget_t* widget, int32_t value) { ret_t scroll_bar_set_value(widget_t* widget, int32_t value) { scroll_bar_t* scroll_bar = SCROLL_BAR(widget); - return_value_if_fail(scroll_bar != NULL || value >= 0, RET_BAD_PARAMS); + return_value_if_fail(scroll_bar != NULL && value >= 0, RET_BAD_PARAMS); if (scroll_bar->value != value) { value_change_event_t evt; diff --git a/src/ext_widgets/serial_widget/serial_widget.c b/src/ext_widgets/serial_widget/serial_widget.c index 39012ad79..7098168e4 100644 --- a/src/ext_widgets/serial_widget/serial_widget.c +++ b/src/ext_widgets/serial_widget/serial_widget.c @@ -142,6 +142,7 @@ static ret_t serial_widget_get_prop(widget_t* widget, const char* name, value_t* static ret_t serial_widget_on_data(widget_t* widget) { serial_widget_t* serial_widget = SERIAL_WIDGET(widget); + ENSURE(serial_widget); widget_dispatch_simple_event(widget, EVT_DATA); if (!tk_object_get_prop_bool(TK_OBJECT(serial_widget->iostream), TK_STREAM_PROP_IS_OK, FALSE)) { @@ -154,6 +155,7 @@ static ret_t serial_widget_on_data(widget_t* widget) { static ret_t serial_widget_close_device(widget_t* widget) { serial_widget_t* serial_widget = SERIAL_WIDGET(widget); + ENSURE(serial_widget); TK_OBJECT_UNREF(serial_widget->iostream); serial_widget->istream = NULL; @@ -193,6 +195,7 @@ static ret_t serial_widget_on_event_source_event(event_source_t* source) { static ret_t serial_widget_check_if_data_available(const timer_info_t* info) { widget_t* widget = WIDGET(info->ctx); serial_widget_t* serial_widget = SERIAL_WIDGET(info->ctx); + ENSURE(serial_widget); if (serial_widget->iostream != NULL) { ret_t ret = tk_iostream_serial_wait_for_data(serial_widget->iostream, 10); @@ -215,6 +218,7 @@ static ret_t serial_widget_apply_props_async(const idle_info_t* info) { int fd = -1; widget_t* widget = WIDGET(info->ctx); serial_widget_t* serial_widget = SERIAL_WIDGET(info->ctx); + ENSURE(serial_widget); serial_widget_close_device(widget); return_value_if_fail(serial_widget->device != NULL, RET_REMOVE); diff --git a/src/ext_widgets/slide_menu/slide_menu.c b/src/ext_widgets/slide_menu/slide_menu.c index e19b915e6..f5c9e732c 100644 --- a/src/ext_widgets/slide_menu/slide_menu.c +++ b/src/ext_widgets/slide_menu/slide_menu.c @@ -109,6 +109,7 @@ static int32_t slide_menu_get_visible_nr(widget_t* widget) { int32_t n = 0; int32_t menu_w = 0; slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); if (widget->w == 0 || widget->h == 0) return 0; menu_w = slide_menu_get_menu_w(slide_menu); @@ -125,6 +126,7 @@ static rect_t slide_menu_get_clip_r(widget_t* widget) { int32_t w = 0; int32_t h = widget->h; slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); if (slide_menu->clip) { int32_t nr = slide_menu_get_visible_nr(widget) - 1; int32_t menu_w = slide_menu_get_menu_w(slide_menu); @@ -282,6 +284,7 @@ static uint32_t slide_menu_get_visible_children(widget_t* widget, int32_t curr = 0; uint32_t nr = widget_count_children(widget); slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); rect_t clip_rect = slide_menu_get_clip_r(widget); int32_t delta_index = slide_menu_get_delta_index(widget); int32_t index = slide_menu_fix_index(widget, slide_menu->value - delta_index); @@ -386,6 +389,7 @@ static ret_t slide_menu_do_layout_children(widget_t* widget) { int32_t visible_nr = MAX_VISIBLE_NR; widget_t* children[MAX_VISIBLE_NR]; slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); int32_t menu_h = widget->h; int32_t menu_w = slide_menu_get_menu_w(slide_menu); int32_t menu_w_s = menu_w + slide_menu->spacer; @@ -450,6 +454,7 @@ static ret_t slide_menu_layout_children(widget_t* widget) { static ret_t slide_menu_get_prop(widget_t* widget, const char* name, value_t* v) { slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); if (tk_str_eq(name, WIDGET_PROP_VALUE)) { value_set_int(v, slide_menu->value); @@ -482,6 +487,7 @@ static ret_t slide_menu_get_prop(widget_t* widget, const char* name, value_t* v) static ret_t slide_menu_set_prop(widget_t* widget, const char* name, const value_t* v) { slide_menu_t* slide_menu = SLIDE_MENU(widget); + ENSURE(slide_menu); if (tk_str_eq(name, WIDGET_PROP_VALUE)) { slide_menu_set_value(widget, value_int(v)); diff --git a/src/ext_widgets/slide_view/slide_view.c b/src/ext_widgets/slide_view/slide_view.c index aa81c51cd..396a7cd7a 100644 --- a/src/ext_widgets/slide_view/slide_view.c +++ b/src/ext_widgets/slide_view/slide_view.c @@ -406,6 +406,7 @@ static uint32_t slide_view_get_page_max_number(widget_t* widget) { static ret_t slide_view_get_prop(widget_t* widget, const char* name, value_t* v) { slide_view_t* slide_view = SLIDE_VIEW(widget); + ENSURE(slide_view); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_VALUE) || tk_str_eq(name, WIDGET_PROP_ACTIVE) || @@ -446,6 +447,7 @@ static ret_t slide_view_get_prop(widget_t* widget, const char* name, value_t* v) static ret_t slide_view_set_prop(widget_t* widget, const char* name, const value_t* v) { slide_view_t* slide_view = SLIDE_VIEW(widget); + ENSURE(slide_view); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_VALUE) || tk_str_eq(name, WIDGET_PROP_ACTIVE) || @@ -812,6 +814,7 @@ static ret_t slide_view_on_idle_init_save_target(const idle_info_t* idle) { slide_view_t* slide_view = NULL; return_value_if_fail(idle != NULL, RET_BAD_PARAMS); slide_view = SLIDE_VIEW(idle->ctx); + ENSURE(slide_view); if (slide_view->widget.focused) { slide_view_restore_target(WIDGET(slide_view)); slide_view->init_idle_id = TK_INVALID_ID; @@ -824,6 +827,7 @@ static ret_t slide_view_on_idle_move(const idle_info_t* idle) { slide_view_t* slide_view = NULL; return_value_if_fail(idle != NULL, RET_BAD_PARAMS); slide_view = SLIDE_VIEW(idle->ctx); + ENSURE(slide_view); if (slide_view->dragged) { widget_invalidate(WIDGET(slide_view), NULL); } @@ -861,6 +865,7 @@ static ret_t slide_view_on_idle_set_target_focused(const idle_info_t* idle) { slide_view_t* slide_view = NULL; return_value_if_fail(idle != NULL, RET_BAD_PARAMS); slide_view = SLIDE_VIEW(idle->ctx); + ENSURE(slide_view); default_focused_child_set_target_focused(&(slide_view->str_target), WIDGET(slide_view)); @@ -968,6 +973,7 @@ static ret_t slide_view_set_active_animate(widget_t* widget, uint32_t active) { ret_t slide_view_set_active_ex(widget_t* widget, uint32_t index, bool_t animate) { slide_view_t* slide_view = SLIDE_VIEW(widget); + ENSURE(slide_view); widget_t* win = widget_get_window(widget); if (widget_count_children(widget) < 2 || slide_view->active == index || !animate || win == NULL) { diff --git a/src/ext_widgets/switch/switch.c b/src/ext_widgets/switch/switch.c index c58c79df7..39539c014 100644 --- a/src/ext_widgets/switch/switch.c +++ b/src/ext_widgets/switch/switch.c @@ -193,6 +193,7 @@ static ret_t switch_on_event(widget_t* widget, event_t* e) { ret_t switch_fill_rect_color(widget_t* widget, canvas_t* c, rect_t* r, bool_t bg) { style_t* style = widget->astyle; switch_t* aswitch = SWITCH(widget); + ENSURE(aswitch); color_t trans = color_init(0, 0, 0, 0); uint32_t radius = style_get_int(style, STYLE_ID_ROUND_RADIUS, 0); const char* color_key = bg ? (aswitch->value ? STYLE_ID_SELECTED_BG_COLOR : STYLE_ID_BG_COLOR) diff --git a/src/ext_widgets/text_selector/text_selector.c b/src/ext_widgets/text_selector/text_selector.c index 97af0d571..ccc9aef6f 100644 --- a/src/ext_widgets/text_selector/text_selector.c +++ b/src/ext_widgets/text_selector/text_selector.c @@ -63,6 +63,7 @@ static ret_t text_selector_paint_mask(widget_t* widget, canvas_t* c) { color_t mask_color = style_get_color(style, STYLE_ID_MASK_COLOR, trans); text_selector_t* text_selector = TEXT_SELECTOR(widget); + ENSURE(text_selector); int32_t visible_nr = text_selector->visible_nr; int32_t item_height = text_selector->draw_widget_h / visible_nr; easing_func_t easing = easing_get(text_selector->mask_easing); @@ -166,6 +167,7 @@ static ret_t text_selector_paint_text(widget_t* widget, canvas_t* c, rect_t* r, uint32_t d = tk_abs(r->y - empty_item_height); text_selector = TEXT_SELECTOR(widget); + ENSURE(text_selector); if (d < item_height) { text_selector_prepare_highlight_style(widget, c, (item_height - d) / (float_t)item_height, diff --git a/src/ext_widgets/time_clock/time_clock.c b/src/ext_widgets/time_clock/time_clock.c index 76e69c17f..a5cd9a657 100644 --- a/src/ext_widgets/time_clock/time_clock.c +++ b/src/ext_widgets/time_clock/time_clock.c @@ -310,6 +310,7 @@ static ret_t time_clock_on_paint_self(widget_t* widget, canvas_t* c) { bitmap_t bitmap; float_t rotation = 0; time_clock_t* time_clock = TIME_CLOCK(widget); + ENSURE(time_clock); rect_t dst = rect_init(0, 0, widget->w, widget->h); if (time_clock_load_image(widget, time_clock->bg_image, &bitmap) == RET_OK) { diff --git a/src/ext_widgets/vpage/vpage.c b/src/ext_widgets/vpage/vpage.c index f5ba4a8b0..34905b853 100644 --- a/src/ext_widgets/vpage/vpage.c +++ b/src/ext_widgets/vpage/vpage.c @@ -173,6 +173,7 @@ static ret_t vpage_on_enter(widget_t* widget, uint32_t index, uint32_t old_index static ret_t vpage_on_leave_done(widget_t* widget) { vpage_t* vpage = VPAGE(widget); + ENSURE(vpage); if (vpage->ui_asset != NULL) { vpage_dispatch_event(widget, EVT_VPAGE_CLOSE); diff --git a/src/tkc/easing.c b/src/tkc/easing.c index 16a6fb200..09d325438 100644 --- a/src/tkc/easing.c +++ b/src/tkc/easing.c @@ -270,7 +270,9 @@ easing_func_t easing_get(easing_type_t type) { uint32_t easing_register(const char* type_name, easing_func_t easing_func) { easing_name_func_t* easing_name_func = TKMEM_ZALLOC(easing_name_func_t); + ENSURE(easing_name_func); easing_name_func->type_name_value = TKMEM_ZALLOC(key_type_value_t); + ENSURE(easing_name_func->type_name_value); easing_name_func->type_name_value->name = tk_str_copy(easing_name_func->type_name_value->name, type_name); diff --git a/src/tkc/fscript.c b/src/tkc/fscript.c index 0aeb7e654..9c19fc269 100644 --- a/src/tkc/fscript.c +++ b/src/tkc/fscript.c @@ -533,6 +533,7 @@ static ret_t fscript_eval_arg(fscript_t* fscript, fscript_func_call_t* iter, uin value_copy(d, s); /*func_set accept id/str as first param*/ } else { const char* name = value_id(s); + ENSURE(name); if (value_id_index(s) >= 0) { return fscript_locals_get(fscript, s, d); } @@ -1437,6 +1438,7 @@ static ret_t token_to_value(fscript_parser_t* parser, token_t* t, value_t* v) { const char* p = NULL; value_set_id(v, t->token, t->size); name = value_id(v); + ENSURE(name); p = strchr(name, '.'); if (p != NULL) { char first_name[TK_NAME_LEN + 1]; diff --git a/src/tkc/object_array.c b/src/tkc/object_array.c index f0f962961..777b8f0ac 100644 --- a/src/tkc/object_array.c +++ b/src/tkc/object_array.c @@ -389,6 +389,7 @@ static tk_object_t* object_array_create_with_capacity(uint32_t init_capacity) { return_value_if_fail(obj != NULL, NULL); if (init_capacity > 0) { object_array_t* o = OBJECT_ARRAY(obj); + ENSURE(o); o->props = TKMEM_ZALLOCN(value_t, init_capacity); if (o->props != NULL) { @@ -563,6 +564,7 @@ tk_object_t* object_array_dup(tk_object_t* obj, uint32_t start, uint32_t end) { ret_t object_array_remove_value(tk_object_t* obj, value_t* v) { uint32_t i = 0; object_array_t* o = OBJECT_ARRAY(obj); + ENSURE(o); return_value_if_fail(obj != NULL && v != NULL, RET_BAD_PARAMS); for (i = 0; i < o->size; i++) { @@ -609,6 +611,7 @@ static int value_cmp_as_str_i_r(const void* a, const void* b) { ret_t object_array_sort(tk_object_t* obj, tk_compare_t cmp) { object_array_t* o = OBJECT_ARRAY(obj); + ENSURE(o); event_t e = event_init(EVT_ITEMS_CHANGED, o); return_value_if_fail(obj != NULL && cmp != NULL, RET_BAD_PARAMS); diff --git a/src/tkc/object_default.c b/src/tkc/object_default.c index 66e9f5ef1..6963371b7 100644 --- a/src/tkc/object_default.c +++ b/src/tkc/object_default.c @@ -83,6 +83,7 @@ static ret_t object_default_set_prop(tk_object_t* obj, const char* name, const v value_t* vv = NULL; ret_t ret = RET_NOT_FOUND; object_default_t* o = OBJECT_DEFAULT(obj); + ENSURE(o); if (o->props.size > 0 && o->enable_path) { tk_object_t* sub = tk_object_get_child_object(obj, name, &name); @@ -214,6 +215,7 @@ static const object_vtable_t s_object_default_vtable = { tk_object_t* object_default_create_ex(bool_t enable_path) { tk_object_t* obj = tk_object_create(&s_object_default_vtable); object_default_t* o = OBJECT_DEFAULT(obj); + ENSURE(o); return_value_if_fail(obj != NULL, NULL); o->enable_path = enable_path; diff --git a/src/tkc/types_def.h b/src/tkc/types_def.h index 0da38e8ef..b3d7b960f 100644 --- a/src/tkc/types_def.h +++ b/src/tkc/types_def.h @@ -318,7 +318,12 @@ typedef enum _ret_t { } #if defined(NDEBUG) || defined(SYLIXOS) +#ifdef WITH_INFERCHECK +#define __INFER_ENSURE__(p) (void)(!!(p) || (exit(0), 0)) +#define ENSURE(p) __INFER_ENSURE__(p) +#else #define ENSURE(p) (void)(p) +#endif #define goto_error_if_fail(p) \ if (!(p)) { \ goto error; \ @@ -399,9 +404,12 @@ typedef ret_t (*tk_callback_t)(void* ctx); enum { TK_NAME_LEN = 31, TK_FUNC_NAME_LEN = 63 }; #ifdef WITH_CPPCHECK -#define tk_str_eq strcmp("abc", "123") -#define tk_str_ieq strcasecmp -#define tk_str_eq_with_len strncmp +int __cppcheck__strcmp(const char* s1, const char* s2); +int __cppcheck__strcasecmp(const char* s1, const char* s2); +int __cppcheck__strncmp(const char* s1, const char* s2, size_t n); +#define tk_str_eq(s1, s2) (__cppcheck__strcmp((s1), (s2)) == 0) +#define tk_str_ieq(s1, s2) (__cppcheck__strcasecmp((s1), (s2)) == 0) +#define tk_str_eq_with_len(s1, s2, len) (__cppcheck__strncmp((s1), (s2), len) == 0) #else #define tk_str_eq(s1, s2) \ (((s1) == NULL && (s2) == NULL) || \ @@ -498,7 +506,7 @@ typedef struct _event_source_manager_t event_source_manager_t; #endif #define tk_isspace(c) ((0 <= (int)(c)) && ((int)(c) < 128) && isspace(c)) -#define tk_isdigit(c) ((0 <= (int)(c)) && ((int)(c) < 128) && isdigit(c)) +#define tk_isdigit(c) ((int)(c) >= '0' && (int)(c) <= '9') #define tk_isxdigit(c) ((0 <= (int)(c)) && ((int)(c) < 128) && isxdigit(c)) #define tk_isprint(c) ((0 <= (int)(c)) && ((int)(c) < 128) && isprint(c)) #define tk_isalpha(c) ((0 <= (int)(c)) && ((int)(c) < 128) && isalpha(c)) diff --git a/src/tkc/utils.c b/src/tkc/utils.c index 731045f45..e900a90e7 100644 --- a/src/tkc/utils.c +++ b/src/tkc/utils.c @@ -880,11 +880,11 @@ const char* tk_under_score_to_camel(const char* name, char* out, uint32_t max_ou } int32_t tk_pointer_to_int(const void* p) { - return (char*)p - (char*)(NULL); + return (int32_t)(intptr_t)p; } void* tk_pointer_from_int(int32_t v) { - return ((char*)NULL) + v; + return (void*)(intptr_t)v; } char* tk_str_toupper(char* str) { @@ -1522,6 +1522,7 @@ ret_t xml_file_expand(const char* filename, str_t* s, const char* data) { int size = 0; char* str_end = NULL; char* include_string_end = strstr(p, "?>"); + ENSURE(include_string_end); if (close_state == XML_PROPERTY_CLOSE_STATE_OPEN_PROPERTY) { str_end = TAG_PROPERTY; size = tk_strlen(TAG_PROPERTY); @@ -1597,7 +1598,7 @@ char* file_read_as_unix_text(const char* filename, uint32_t* size) { } #endif /*WITH_WASM*/ -static const char* s_ret_names[] = {[RET_OK] = "RET_OK", +static const char* s_ret_names[RET_MAX_NR] = {[RET_OK] = "RET_OK", [RET_OOM] = "RET_OOM", [RET_FAIL] = "RET_FAIL", [RET_NOT_IMPL] = "RET_NOT_IMPL", @@ -1635,7 +1636,7 @@ ret_t ret_code_from_name(const char* name) { } const char* ret_code_to_name(ret_t ret) { - if (ret >= RET_OK && ret <= RET_MAX_NR) { + if (ret >= RET_OK && ret < RET_MAX_NR) { return s_ret_names[ret]; } else { return ""; diff --git a/src/ui_loader/ui_builder_default.c b/src/ui_loader/ui_builder_default.c index f1d2f91fe..569fe8128 100644 --- a/src/ui_loader/ui_builder_default.c +++ b/src/ui_loader/ui_builder_default.c @@ -79,9 +79,10 @@ static ret_t ui_builder_default_on_widget_end(ui_builder_t* b) { } static ret_t ui_builder_default_on_end(ui_builder_t* b) { - if (b->root != NULL) { + ENSURE(b); + widget_t* widget = b->root; + if (widget != NULL) { event_t e; - widget_t* widget = b->root; widget_invalidate_force(widget, NULL); if (widget && (widget->name == NULL || widget->name[0] == 0)) { diff --git a/src/widgets/button.c b/src/widgets/button.c index 407d97e66..e15b46998 100644 --- a/src/widgets/button.c +++ b/src/widgets/button.c @@ -62,6 +62,7 @@ static ret_t button_notify_pressed_changed(widget_t* widget) { value_t v; prop_change_event_t e; button_t* button = BUTTON(widget); + ENSURE(button); e.e = event_init(EVT_PROP_CHANGED, widget); e.name = "pressed"; @@ -153,6 +154,7 @@ static ret_t button_draw_preview(void* ctx, event_t* e) { widget_t* widget = WIDGET(ctx); point_t p = {0, 0}; paint_event_t* evt = paint_event_cast(e); + ENSURE(evt); canvas_t* c = evt->c; int32_t ox = c->ox; int32_t oy = c->oy; @@ -239,6 +241,7 @@ static ret_t button_on_event(widget_t* widget, event_t* e) { case EVT_POINTER_UP: { pointer_event_t click; pointer_event_t* up = pointer_event_cast(e); + ENSURE(up); pointer_event_init(&click, EVT_CLICK, widget, up->x, up->y); if (button->pressed && widget_is_point_in(widget, click.x, click.y, FALSE)) { diff --git a/src/widgets/check_button.c b/src/widgets/check_button.c index 579797df9..4381f2928 100644 --- a/src/widgets/check_button.c +++ b/src/widgets/check_button.c @@ -126,6 +126,7 @@ ret_t check_button_set_value(widget_t* widget, bool_t value) { static ret_t check_button_get_prop(widget_t* widget, const char* name, value_t* v) { check_button_t* check_button = CHECK_BUTTON(widget); + ENSURE(check_button); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_VALUE)) { diff --git a/src/widgets/color_tile.c b/src/widgets/color_tile.c index 135dd6576..e30584a16 100644 --- a/src/widgets/color_tile.c +++ b/src/widgets/color_tile.c @@ -131,6 +131,7 @@ static ret_t color_tile_on_paint_self(widget_t* widget, canvas_t* c) { static ret_t color_tile_get_prop(widget_t* widget, const char* name, value_t* v) { color_tile_t* color_tile = COLOR_TILE(widget); + ENSURE(color_tile); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_BG_COLOR)) { diff --git a/src/widgets/combo_box.c b/src/widgets/combo_box.c index 567deb8cf..a4b60105e 100644 --- a/src/widgets/combo_box.c +++ b/src/widgets/combo_box.c @@ -419,6 +419,7 @@ static ret_t combo_box_on_key_event(widget_t* widget, key_event_t* evt) { static ret_t combo_box_init_popup_button(widget_t* widget) { widget_t* popup = button_create(widget, 0, 0, 0, 0); + ENSURE(popup); popup->auto_created = TRUE; widget_use_style(popup, "combobox_down"); widget_invalidate_force(widget, NULL); @@ -521,6 +522,7 @@ static ret_t combo_box_on_idle_init_popup_button(const idle_info_t* idle) { widget = WIDGET(idle->ctx); combo_box = COMBO_BOX(widget); + ENSURE(combo_box); if (!widget->destroying) { widget_t* button = widget_lookup_by_type(widget, WIDGET_TYPE_BUTTON, TRUE); @@ -536,6 +538,7 @@ static ret_t combo_box_on_idle_init_popup_button(const idle_info_t* idle) { static ret_t combo_box_idle_init_popup_button(widget_t* widget) { combo_box_t* combo_box = COMBO_BOX(widget); + ENSURE(combo_box); if (combo_box->init_popup_button_idle_id == TK_INVALID_ID) { combo_box->init_popup_button_idle_id = idle_add(combo_box_on_idle_init_popup_button, widget); } @@ -605,6 +608,7 @@ static ret_t combo_box_on_item_click(void* ctx, event_t* e) { widget_t* widget = WIDGET(ctx); widget_t* item = WIDGET(e->target); combo_box_t* combo_box = COMBO_BOX(ctx); + ENSURE(combo_box); return_value_if_fail(widget != NULL && item != NULL, RET_BAD_PARAMS); if (combo_box->on_item_click != NULL) { @@ -874,6 +878,7 @@ ret_t combo_box_reset_options(widget_t* widget) { ret_t combo_box_set_open_window(widget_t* widget, const char* open_window) { combo_box_t* combo_box = COMBO_BOX(widget); + ENSURE(combo_box); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); TKMEM_FREE(combo_box->open_window); @@ -884,6 +889,7 @@ ret_t combo_box_set_open_window(widget_t* widget, const char* open_window) { ret_t combo_box_set_theme_of_popup(widget_t* widget, const char* theme_of_popup) { combo_box_t* combo_box = COMBO_BOX(widget); + ENSURE(combo_box); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); TKMEM_FREE(combo_box->theme_of_popup); @@ -1077,6 +1083,7 @@ static ret_t combo_box_set_selected_index_ex(widget_t* widget, uint32_t index, w static ret_t combo_box_add_selected_index(widget_t* widget, int32_t delta) { combo_box_t* combo_box = COMBO_BOX(widget); + ENSURE(combo_box); uint32_t nr = combo_box_count_options(widget); if (nr > 0) { diff --git a/src/widgets/dialog_toast.inc b/src/widgets/dialog_toast.inc index 4f6abbdd3..414e32e2c 100644 --- a/src/widgets/dialog_toast.inc +++ b/src/widgets/dialog_toast.inc @@ -227,7 +227,7 @@ static dialog_toast_t* dialog_toast_manager() { static ret_t dialog_toast_on_idle_close(const idle_info_t* info) { dialog_toast_t* dialog_toast = DIALOG_TOAST(info->ctx); - ENSURE(dialog_toast != NULL); + ENSURE(dialog_toast); if (!dialog_toast->is_opened) { return RET_REPEAT; } diff --git a/src/widgets/digit_clock.c b/src/widgets/digit_clock.c index 18660860b..64a94d18c 100644 --- a/src/widgets/digit_clock.c +++ b/src/widgets/digit_clock.c @@ -71,6 +71,7 @@ static ret_t digit_clock_on_display_time(void* ctx, event_t* e) { ret_t digit_clock_set_format(widget_t* widget, const char* format) { digit_clock_t* digit_clock = DIGIT_CLOCK(widget); + ENSURE(digit_clock); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); digit_clock->format = tk_str_copy(digit_clock->format, format); @@ -81,6 +82,7 @@ ret_t digit_clock_set_format(widget_t* widget, const char* format) { static ret_t digit_clock_get_prop(widget_t* widget, const char* name, value_t* v) { digit_clock_t* digit_clock = DIGIT_CLOCK(widget); + ENSURE(digit_clock); return_value_if_fail(widget != NULL && name != NULL && v != NULL, RET_BAD_PARAMS); if (tk_str_eq(name, WIDGET_PROP_FORMAT)) { diff --git a/src/widgets/edit.c b/src/widgets/edit.c index 34b46f7f3..af717ba95 100644 --- a/src/widgets/edit.c +++ b/src/widgets/edit.c @@ -366,6 +366,7 @@ static bool_t edit_is_number(widget_t* widget) { static bool_t edit_is_size_valid(widget_t* widget) { edit_t* edit = EDIT(widget); + ENSURE(edit); uint32_t size = widget->text.size; uint32_t min = (uint32_t)(edit->min); uint32_t max = (uint32_t)(edit->max); @@ -533,6 +534,7 @@ static ret_t edit_auto_fix_default(widget_t* widget) { static ret_t edit_update_status(widget_t* widget) { edit_t* edit = EDIT(widget); + ENSURE(edit); if (widget->text.size == 0) { if (widget->focused) { widget_set_state(widget, WIDGET_STATE_EMPTY_FOCUS); @@ -1401,6 +1403,7 @@ static ret_t edit_set_text(widget_t* widget, const value_t* v) { wstr_t str; wstr_init(&str, 0); edit_t* edit = EDIT(widget); + ENSURE(edit); return_value_if_fail(wstr_from_value(&str, v) == RET_OK, RET_BAD_PARAMS); if (!wstr_equal(&(widget->text), &str)) { diff --git a/src/widgets/grid.c b/src/widgets/grid.c index e2fe44330..5d15c2b6f 100644 --- a/src/widgets/grid.c +++ b/src/widgets/grid.c @@ -306,6 +306,7 @@ static ret_t grid_on_layout_children_impl(widget_t* widget) { static ret_t grid_on_layout_children(widget_t* widget) { grid_t* grid = GRID(widget); + ENSURE(grid); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); if (widget->children_layout != NULL) { @@ -358,6 +359,7 @@ static ret_t grid_draw_grid(widget_t* widget, canvas_t* c) { static ret_t grid_on_paint_border(widget_t* widget, canvas_t* c) { grid_t* grid = GRID(widget); + ENSURE(grid); if (grid->show_grid && widget->astyle != NULL) { rect_t r = rect_init(0, 0, widget->w, widget->h); diff --git a/src/widgets/label.c b/src/widgets/label.c index 5fe782d69..25b3de1f7 100644 --- a/src/widgets/label.c +++ b/src/widgets/label.c @@ -80,6 +80,7 @@ static ret_t label_paint_text(widget_t* widget, canvas_t* c, const wchar_t* str, line_parser_t p; ret_t ret = RET_OK; label_t* label = LABEL(widget); + ENSURE(label); rect_t r = widget_get_content_area_ex(widget, 0); return_value_if_fail((r.w > 0 && widget->h >= c->font_size), RET_FAIL); @@ -102,6 +103,7 @@ static ret_t label_paint_text(widget_t* widget, canvas_t* c, const wchar_t* str, static ret_t label_on_paint_self(widget_t* widget, canvas_t* c) { if (widget->text.size > 0 && style_is_valid(widget->astyle)) { label_t* label = LABEL(widget); + ENSURE(label); uint32_t size = label->length >= 0 ? tk_min(label->length, widget->text.size) : widget->text.size; @@ -241,6 +243,7 @@ static ret_t label_auto_adjust_size_impl(widget_t* widget, canvas_t* c, uint32_t wh_t max_line_w = 0; int32_t line_height = 0; label_t* label = LABEL(widget); + ENSURE(label); style_t* style = widget->astyle; int32_t margin = style_get_int(style, STYLE_ID_MARGIN, 2); int32_t margin_top = style_get_int(style, STYLE_ID_MARGIN_TOP, margin); diff --git a/src/widgets/pages.c b/src/widgets/pages.c index e75701506..c0a541806 100644 --- a/src/widgets/pages.c +++ b/src/widgets/pages.c @@ -53,6 +53,7 @@ static ret_t pages_on_idle_set_target_focused(const idle_info_t* idle) { pages_t* pages = NULL; return_value_if_fail(idle != NULL, RET_BAD_PARAMS); pages = PAGES(idle->ctx); + ENSURE(pages); default_focused_child_set_target_focused(&(pages->str_target), WIDGET(pages)); @@ -95,6 +96,7 @@ static ret_t pages_restore_target(widget_t* widget) { static ret_t pages_show_active(widget_t* widget) { pages_t* pages = PAGES(widget); + ENSURE(pages); WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i) widget_set_visible(iter, i == pages->active); WIDGET_FOR_EACH_CHILD_END() @@ -222,6 +224,7 @@ static ret_t pages_on_idle_init_save_target(const idle_info_t* idle) { pages_t* pages = NULL; return_value_if_fail(idle != NULL, RET_BAD_PARAMS); pages = PAGES(idle->ctx); + ENSURE(pages); pages_restore_target(WIDGET(pages)); pages->init_idle_id = TK_INVALID_ID; diff --git a/src/widgets/progress_bar.c b/src/widgets/progress_bar.c index 5cead06f4..fbb94ee5a 100644 --- a/src/widgets/progress_bar.c +++ b/src/widgets/progress_bar.c @@ -45,6 +45,7 @@ static ret_t progress_bar_on_paint_self(widget_t* widget, canvas_t* c) { rect_t r; style_t* style = widget->astyle; progress_bar_t* progress_bar = PROGRESS_BAR(widget); + ENSURE(progress_bar); uint32_t radius = style_get_int(style, STYLE_ID_ROUND_RADIUS, 0); const char* bg_image = style_get_str(style, STYLE_ID_BG_IMAGE, NULL); image_draw_type_t draw_type = progress_bar->vertical ? IMAGE_DRAW_PATCH3_Y : IMAGE_DRAW_PATCH3_X; diff --git a/src/widgets/slider.c b/src/widgets/slider.c index b844ee28d..bbfc337b2 100644 --- a/src/widgets/slider.c +++ b/src/widgets/slider.c @@ -51,6 +51,7 @@ static uint32_t slider_get_bar_size(widget_t* widget) { static uint32_t slider_get_dragger_size(widget_t* widget) { bitmap_t img; slider_t* slider = SLIDER(widget); + ENSURE(slider); uint32_t dragger_size = slider->dragger_size; if (slider->auto_get_dragger_size) { dragger_size = slider_get_bar_size(widget) * 1.5f; @@ -69,6 +70,7 @@ static rect_t slider_get_dirty_rect(widget_t* widget) { int32_t tolerance = 0; uint32_t dragger_size = 0; slider_t* slider = SLIDER(widget); + ENSURE(slider); rect_t r = rect_init(widget->x, widget->y, widget->w, widget->h); if (widget->initializing) { @@ -258,6 +260,7 @@ static ret_t slider_paint_dragger(widget_t* widget, canvas_t* c) { uint32_t radius; style_t* style = widget->astyle; slider_t* slider = SLIDER(widget); + ENSURE(slider); rect_t* r = &(slider->dragger_rect); color_t trans = color_init(0, 0, 0, 0); @@ -428,6 +431,7 @@ static ret_t slider_change_value_by_pointer_event(widget_t* widget, pointer_even uint32_t max_gap = 0; point_t p = {evt->x, evt->y}; slider_t* slider = SLIDER(widget); + ENSURE(slider); double range = slider->max - slider->min; uint32_t dragger_size = slider_get_dragger_size(widget); int32_t margin = slider->no_dragger_icon ? 0 : style_get_int(widget->astyle, STYLE_ID_MARGIN, 0); diff --git a/src/widgets/tab_button.c b/src/widgets/tab_button.c index f8a4ee749..77b933f23 100644 --- a/src/widgets/tab_button.c +++ b/src/widgets/tab_button.c @@ -223,6 +223,7 @@ ret_t tab_button_set_value(widget_t* widget, bool_t value) { ret_t tab_button_set_load_ui(widget_t* widget, const char* name) { tab_button_t* tab_button = TAB_BUTTON(widget); + ENSURE(tab_button); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); tab_button->load_ui = tk_str_copy(tab_button->load_ui, name); @@ -232,6 +233,7 @@ ret_t tab_button_set_load_ui(widget_t* widget, const char* name) { static int32_t tab_button_get_min_w(widget_t* widget) { tab_button_t* tab_button = TAB_BUTTON(widget); + ENSURE(tab_button); int32_t text_w = widget_measure_text(widget, widget->text.str) + widget->h / 2; if (widget->astyle != NULL) { @@ -316,6 +318,7 @@ TK_DECL_VTABLE(tab_button) = {.size = sizeof(tab_button_t), ret_t tab_button_set_icon(widget_t* widget, const char* name) { tab_button_t* tab_button = TAB_BUTTON(widget); + ENSURE(tab_button); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); TKMEM_FREE(tab_button->icon); @@ -326,6 +329,7 @@ ret_t tab_button_set_icon(widget_t* widget, const char* name) { ret_t tab_button_set_active_icon(widget_t* widget, const char* name) { tab_button_t* tab_button = TAB_BUTTON(widget); + ENSURE(tab_button); return_value_if_fail(widget != NULL, RET_BAD_PARAMS); TKMEM_FREE(tab_button->active_icon); diff --git a/src/widgets/tab_button_group.c b/src/widgets/tab_button_group.c index 5cd98be8d..5bbcb9c21 100644 --- a/src/widgets/tab_button_group.c +++ b/src/widgets/tab_button_group.c @@ -109,6 +109,7 @@ static ret_t tab_button_group_on_layout_children_compact(widget_t* widget) { static ret_t tab_button_group_on_layout_children(widget_t* widget) { tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget); + ENSURE(tab_button_group); if (widget->children && widget->children->size > 0) { if (tab_button_group->compact) { return tab_button_group_on_layout_children_compact(widget); @@ -302,6 +303,7 @@ TK_DECL_VTABLE(tab_button_group) = {.size = sizeof(tab_button_group_t), widget_t* tab_button_group_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) { widget_t* widget = widget_create(parent, TK_REF_VTABLE(tab_button_group), x, y, w, h); tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget); + ENSURE(tab_button_group); return_value_if_fail(widget != NULL, NULL); tab_button_group->hscrollable = hscrollable_create(widget); diff --git a/staticcheck/infer/run.py b/staticcheck/infer/run.py index 2e745a9ca..788268e44 100644 --- a/staticcheck/infer/run.py +++ b/staticcheck/infer/run.py @@ -3,5 +3,5 @@ import sys sys.path.append("../common") import awtk_files as awtk; -CPPFLAGS = 'run -- clang -c -DHAS_STD_MALLOC -DNDEBUG ' +CPPFLAGS = 'run -- clang -c -DHAS_STD_MALLOC -DNDEBUG -DWITH_INFERCHECK ' awtk.run('infer', CPPFLAGS, awtk.getInferFiles())