diff --git a/lv_core/lv_group.c b/lv_core/lv_group.c index a6f911dc2..0d710a1e1 100644 --- a/lv_core/lv_group.c +++ b/lv_core/lv_group.c @@ -43,6 +43,8 @@ static void style_mod_edit_def(lv_style_t * style); lv_group_t * lv_group_create(void) { lv_group_t * group = lv_mem_alloc(sizeof(lv_group_t)); + lv_mem_assert(group); + if(group == NULL) return NULL; lv_ll_init(&group->obj_ll, sizeof(lv_obj_t *)); group->style_mod = style_mod_def; @@ -90,6 +92,8 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) obj->group_p = group; lv_obj_t ** next = lv_ll_ins_tail(&group->obj_ll); + lv_mem_assert(next); + if(next == NULL) return; *next = obj; /* If the head and the tail is equal then there is only one object in the linked list. diff --git a/lv_core/lv_obj.c b/lv_core/lv_obj.c index 892f6020a..923002eb9 100644 --- a/lv_core/lv_obj.c +++ b/lv_core/lv_obj.c @@ -128,6 +128,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) /*Create a screen if the parent is NULL*/ if(parent == NULL) { new_obj = lv_ll_ins_head(&scr_ll); + lv_mem_assert(new_obj); + if(new_obj == NULL) return NULL; new_obj->par = NULL; /*Screens has no a parent*/ lv_ll_init(&(new_obj->child_ll), sizeof(lv_obj_t)); @@ -178,6 +180,9 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, lv_obj_t * copy) /*parent != NULL create normal obj. on a parent*/ else { new_obj = lv_ll_ins_head(&(parent)->child_ll); + lv_mem_assert(new_obj); + if(new_obj == NULL) return NULL; + new_obj->par = parent; /*Set the parent*/ lv_ll_init(&(new_obj->child_ll), sizeof(lv_obj_t)); diff --git a/lv_core/lv_style.c b/lv_core/lv_style.c index 3866a2da7..daa8ee116 100644 --- a/lv_core/lv_style.c +++ b/lv_core/lv_style.c @@ -226,6 +226,9 @@ void * lv_style_anim_create(lv_style_anim_t * anim) { lv_style_anim_dsc_t * dsc; dsc = lv_mem_alloc(sizeof(lv_style_anim_dsc_t)); + lv_mem_assert(dsc); + if(dsc == NULL) return NULL; + dsc->style_anim = anim->style_anim; memcpy(&dsc->style_start, anim->style_start, sizeof(lv_style_t)); memcpy(&dsc->style_end, anim->style_end, sizeof(lv_style_t)); diff --git a/lv_hal/lv_hal_disp.c b/lv_hal/lv_hal_disp.c index ea15ff070..8c8e699a2 100644 --- a/lv_hal/lv_hal_disp.c +++ b/lv_hal/lv_hal_disp.c @@ -70,7 +70,8 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) lv_disp_t * node; node = lv_mem_alloc(sizeof(lv_disp_t)); - if(!node) return NULL; + lv_mem_assert(node); + if(node == NULL) return NULL; memcpy(&node->driver, driver, sizeof(lv_disp_drv_t)); node->next = NULL; diff --git a/lv_misc/lv_anim.c b/lv_misc/lv_anim.c index 54b11b17f..9b271289f 100644 --- a/lv_misc/lv_anim.c +++ b/lv_misc/lv_anim.c @@ -68,6 +68,7 @@ void lv_anim_create(lv_anim_t * anim_p) /*Add the new animation to the animation linked list*/ lv_anim_t * new_anim = lv_ll_ins_head(&anim_ll); lv_mem_assert(new_anim); + if(new_anim == NULL) return; /*Initialize the animation descriptor*/ anim_p->playback_now = 0; diff --git a/lv_misc/lv_fs.c b/lv_misc/lv_fs.c index 68af87cf0..139e11554 100644 --- a/lv_misc/lv_fs.c +++ b/lv_misc/lv_fs.c @@ -82,6 +82,7 @@ lv_fs_res_t lv_fs_open(lv_fs_file_t * file_p, const char * path, lv_fs_mode_t mo } file_p->file_d = lv_mem_alloc(file_p->drv->file_size); + lv_mem_assert(file_p->file_d); if(file_p->file_d == NULL) { file_p->drv = NULL; return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ @@ -286,6 +287,7 @@ lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) } rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size); + lv_mem_assert(rddir_p->dir_d); if(rddir_p->dir_d == NULL) { rddir_p->dir_d = NULL; return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ @@ -392,8 +394,9 @@ void lv_fs_add_drv(lv_fs_drv_t * drv_p) lv_fs_drv_t * new_drv; new_drv = lv_ll_ins_head(&drv_ll); lv_mem_assert(new_drv); - memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); + if(new_drv == NULL) return; + memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); } /** diff --git a/lv_misc/lv_ll.c b/lv_misc/lv_ll.c index c345eda4a..185157d9f 100644 --- a/lv_misc/lv_ll.c +++ b/lv_misc/lv_ll.c @@ -103,9 +103,10 @@ void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act) if(lv_ll_get_head(ll_p) == n_act) { n_new = lv_ll_ins_head(ll_p); + if(n_new == NULL) return NULL; } else { n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); - lv_mem_assert(n_new); + if(n_new == NULL) return NULL; n_prev = lv_ll_get_prev(ll_p, n_act); node_set_next(ll_p, n_prev, n_new); @@ -127,6 +128,7 @@ void * lv_ll_ins_tail(lv_ll_t * ll_p) lv_ll_node_t * n_new; n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); + if(n_new == NULL) return NULL; if(n_new != NULL) { node_set_next(ll_p, n_new, NULL); /*No next after the new tail*/ diff --git a/lv_misc/lv_task.c b/lv_misc/lv_task.c index 9e1488f54..9efead715 100644 --- a/lv_misc/lv_task.c +++ b/lv_misc/lv_task.c @@ -147,10 +147,14 @@ lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t tmp = lv_ll_get_head(&lv_task_ll); if(NULL == tmp) { /*First task*/ new_lv_task = lv_ll_ins_head(&lv_task_ll); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; } else { do { if(tmp->prio <= prio) { new_lv_task = lv_ll_ins_prev(&lv_task_ll, tmp); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; break; } tmp = lv_ll_get_next(&lv_task_ll, tmp); @@ -158,11 +162,11 @@ lv_task_t * lv_task_create(void (*task)(void *), uint32_t period, lv_task_prio_t if(tmp == NULL) { /*Only too high priority tasks were found*/ new_lv_task = lv_ll_ins_tail(&lv_task_ll); + lv_mem_assert(new_lv_task); + if(new_lv_task == NULL) return NULL; } } - lv_mem_assert(new_lv_task); - new_lv_task->period = period; new_lv_task->task = task; new_lv_task->prio = prio; diff --git a/lv_misc/lv_ufs.c b/lv_misc/lv_ufs.c index 5045c2719..4b28fbf6c 100644 --- a/lv_misc/lv_ufs.c +++ b/lv_misc/lv_ufs.c @@ -488,11 +488,13 @@ static lv_ufs_ent_t * lv_ufs_ent_new(const char * fn) { lv_ufs_ent_t * new_ent = NULL; new_ent = lv_ll_ins_head(&file_ll); /*Create a new file*/ - if(new_ent == NULL) { - return NULL; - } + lv_mem_assert(new_ent); + if(new_ent == NULL) return NULL; new_ent->fn_d = lv_mem_alloc(strlen(fn) + 1); /*Save the name*/ + lv_mem_assert(new_ent->fn_d); + if(new_ent->fn_d == NULL) return NULL; + strcpy(new_ent->fn_d, fn); new_ent->data_d = NULL; new_ent->size = 0; diff --git a/lv_objx/lv_arc.c b/lv_objx/lv_arc.c index 5314e99ac..b26929d88 100644 --- a/lv_objx/lv_arc.c +++ b/lv_objx/lv_arc.c @@ -53,10 +53,13 @@ lv_obj_t * lv_arc_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of arc*/ lv_obj_t * new_arc = lv_obj_create(par, copy); lv_mem_assert(new_arc); + if(new_arc == NULL) return NULL; /*Allocate the arc type specific extended data*/ lv_arc_ext_t * ext = lv_obj_allocate_ext_attr(new_arc, sizeof(lv_arc_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_arc); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_arc); diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 7cc84c951..24ba5f2bd 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -55,6 +55,7 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor basic object*/ lv_obj_t * new_bar = lv_obj_create(par, copy); lv_mem_assert(new_bar); + if(new_bar== NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_bar); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_bar); @@ -62,6 +63,8 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the object type specific extended data*/ lv_bar_ext_t * ext = lv_obj_allocate_ext_attr(new_bar, sizeof(lv_bar_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->min_value = 0; ext->max_value = 100; ext->cur_value = 0; diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index b72469e90..d59771105 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -71,12 +71,16 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy) new_btn = lv_cont_create(par, copy); lv_mem_assert(new_btn); + if(new_btn == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_btn); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_btn); /*Allocate the extended data*/ lv_btn_ext_t * ext = lv_obj_allocate_ext_attr(new_btn, sizeof(lv_btn_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->state = LV_BTN_STATE_REL; ext->actions[LV_BTN_ACTION_PR] = NULL; diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index fdccadb7d..d1c39c45d 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -67,11 +67,15 @@ lv_obj_t * lv_btnm_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor object*/ lv_obj_t * new_btnm = lv_obj_create(par, copy); lv_mem_assert(new_btnm); + if(new_btnm == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_btnm); /*Allocate the object type specific extended data*/ lv_btnm_ext_t * ext = lv_obj_allocate_ext_attr(new_btnm, sizeof(lv_btnm_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->btn_cnt = 0; ext->btn_id_pr = LV_BTNM_PR_NONE; ext->btn_id_tgl = LV_BTNM_PR_NONE; @@ -693,6 +697,9 @@ static void create_buttons(lv_obj_t * btnm, const char ** map) } ext->button_areas = lv_mem_alloc(sizeof(lv_area_t) * btn_cnt); + lv_mem_assert(ext->button_areas); + if(ext->button_areas == NULL) btn_cnt = 0; + ext->btn_cnt = btn_cnt; } diff --git a/lv_objx/lv_calendar.c b/lv_objx/lv_calendar.c index 66cdc7154..c76d7d6f3 100644 --- a/lv_objx/lv_calendar.c +++ b/lv_objx/lv_calendar.c @@ -73,10 +73,12 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of calendar*/ lv_obj_t * new_calendar = lv_obj_create(par, copy); lv_mem_assert(new_calendar); + if(new_calendar == NULL) return NULL; /*Allocate the calendar type specific extended data*/ lv_calendar_ext_t * ext = lv_obj_allocate_ext_attr(new_calendar, sizeof(lv_calendar_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_calendar); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_calendar); diff --git a/lv_objx/lv_cb.c b/lv_objx/lv_cb.c index 604aa7573..ba847397c 100644 --- a/lv_objx/lv_cb.c +++ b/lv_objx/lv_cb.c @@ -53,11 +53,15 @@ lv_obj_t * lv_cb_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor basic object*/ lv_obj_t * new_cb = lv_btn_create(par, copy); lv_mem_assert(new_cb); + if(new_cb == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_cb); if(ancestor_bg_design == NULL) ancestor_bg_design = lv_obj_get_design_func(new_cb); lv_cb_ext_t * ext = lv_obj_allocate_ext_attr(new_cb, sizeof(lv_cb_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->bullet = NULL; ext->label = NULL; diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index 1a3a499de..f1bc57592 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -60,10 +60,13 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor basic object*/ lv_obj_t * new_chart = lv_obj_create(par, copy); lv_mem_assert(new_chart); + if(new_chart == NULL) return NULL; /*Allocate the object type specific extended data*/ lv_chart_ext_t * ext = lv_obj_allocate_ext_attr(new_chart, sizeof(lv_chart_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + lv_ll_init(&ext->series_ll, sizeof(lv_chart_series_t)); ext->series.num = 0; ext->ymin = LV_CHART_YMIN_DEF; @@ -125,6 +128,9 @@ lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color) { lv_chart_ext_t * ext = lv_obj_get_ext_attr(chart); lv_chart_series_t * ser = lv_ll_ins_head(&ext->series_ll); + lv_mem_assert(ser); + if(ser == NULL) return NULL; + lv_coord_t def = (ext->ymin + ext->ymax) >> 1; /*half range as default value*/ if(ser == NULL) return NULL; @@ -132,6 +138,12 @@ lv_chart_series_t * lv_chart_add_series(lv_obj_t * chart, lv_color_t color) ser->color = color; ser->points = lv_mem_alloc(sizeof(lv_coord_t) * ext->point_cnt); + lv_mem_assert(ser->points); + if(ser->points == NULL) { + lv_ll_rem(&ext->series_ll, ser); + lv_mem_free(ser); + return NULL; + } uint16_t i; lv_coord_t * p_tmp = ser->points; diff --git a/lv_objx/lv_cont.c b/lv_objx/lv_cont.c index cbe3fce65..2205dc133 100644 --- a/lv_objx/lv_cont.c +++ b/lv_objx/lv_cont.c @@ -65,10 +65,14 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, lv_obj_t * copy) /*Create a basic object*/ lv_obj_t * new_cont = lv_obj_create(par, copy); lv_mem_assert(new_cont); + if(new_cont == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_cont); lv_obj_allocate_ext_attr(new_cont, sizeof(lv_cont_ext_t)); lv_cont_ext_t * ext = lv_obj_get_ext_attr(new_cont); + if(ext == NULL) return NULL; + lv_mem_assert(ext); ext->hor_fit = 0; ext->ver_fit = 0; diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index 7dcf2e40c..99621fb63 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -69,6 +69,8 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor drop down list*/ lv_obj_t * new_ddlist = lv_page_create(par, copy); lv_mem_assert(new_ddlist); + if(new_ddlist == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ddlist); if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ddlist)); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ddlist); @@ -76,6 +78,7 @@ lv_obj_t * lv_ddlist_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the drop down list type specific extended data*/ lv_ddlist_ext_t * ext = lv_obj_allocate_ext_attr(new_ddlist, sizeof(lv_ddlist_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->label = NULL; diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 4cf73e65a..cd3306eff 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -63,10 +63,12 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor gauge*/ lv_obj_t * new_gauge = lv_lmeter_create(par, copy); lv_mem_assert(new_gauge); + if(new_gauge == NULL) return NULL; /*Allocate the gauge type specific extended data*/ lv_gauge_ext_t * ext = lv_obj_allocate_ext_attr(new_gauge, sizeof(lv_gauge_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->needle_count = 0; diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index f26b479e9..06d72c28e 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -59,11 +59,15 @@ lv_obj_t * lv_img_create(lv_obj_t * par, lv_obj_t * copy) /*Create a basic object*/ new_img = lv_obj_create(par, copy); lv_mem_assert(new_img); + if(new_img == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_img); /*Extend the basic object to image object*/ lv_img_ext_t * ext = lv_obj_allocate_ext_attr(new_img, sizeof(lv_img_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->src = NULL; ext->src_type = LV_IMG_SRC_UNKNOWN; ext->w = lv_obj_get_width(new_img); @@ -167,6 +171,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) if(ext->src != src_img) { lv_mem_free(ext->src); char * new_fn = lv_mem_alloc(strlen(src_img) + 1); + lv_mem_assert(new_fn); + if(new_fn == NULL) return; strcpy(new_fn, src_img); ext->src = new_fn; @@ -185,6 +191,8 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) if(ext->src != src_img) { lv_mem_free(ext->src); char * new_txt = lv_mem_alloc(strlen(src_img) + 1); + lv_mem_assert(new_txt); + if(new_txt == NULL) return; strcpy(new_txt, src_img); ext->src = new_txt; } diff --git a/lv_objx/lv_kb.c b/lv_objx/lv_kb.c index 455b25b20..6caf32538 100644 --- a/lv_objx/lv_kb.c +++ b/lv_objx/lv_kb.c @@ -78,11 +78,14 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of keyboard*/ lv_obj_t * new_kb = lv_btnm_create(par, copy); lv_mem_assert(new_kb); + if(new_kb == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_kb); /*Allocate the keyboard type specific extended data*/ lv_kb_ext_t * ext = lv_obj_allocate_ext_attr(new_kb, sizeof(lv_kb_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 0cda61a08..2a4aa0a37 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -67,6 +67,8 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) /*Create a basic object*/ lv_obj_t * new_label = lv_obj_create(par, copy); lv_mem_assert(new_label); + if(new_label == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_label); /*Extend the basic object to a label object*/ @@ -74,6 +76,8 @@ lv_obj_t * lv_label_create(lv_obj_t * par, lv_obj_t * copy) lv_label_ext_t * ext = lv_obj_get_ext_attr(new_label); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->text = NULL; ext->static_txt = 0; ext->recolor = 0; @@ -153,6 +157,9 @@ void lv_label_set_text(lv_obj_t * label, const char * text) } ext->text = lv_mem_alloc(len); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + strcpy(ext->text, text); ext->static_txt = 0; /*Now the text is dynamically allocated*/ } @@ -184,6 +191,9 @@ void lv_label_set_array_text(lv_obj_t * label, const char * array, uint16_t size ext->text = NULL; } ext->text = lv_mem_alloc(size + 1); + lv_mem_assert(ext->text); + if(ext->text == NULL) return; + memcpy(ext->text, array, size); ext->text[size] = '\0'; ext->static_txt = 0; /*Now the text is dynamically allocated*/ diff --git a/lv_objx/lv_led.c b/lv_objx/lv_led.c index 985534da9..0c5c3a6f3 100644 --- a/lv_objx/lv_led.c +++ b/lv_objx/lv_led.c @@ -55,12 +55,16 @@ lv_obj_t * lv_led_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor basic object*/ lv_obj_t * new_led = lv_obj_create(par, copy); lv_mem_assert(new_led); + if(new_led == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_led); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_led); /*Allocate the object type specific extended data*/ lv_led_ext_t * ext = lv_obj_allocate_ext_attr(new_led, sizeof(lv_led_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->bright = LV_LED_BRIGHT_ON; lv_obj_set_signal_func(new_led, lv_led_signal); diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index cef87180e..17dfd2b5d 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -53,11 +53,15 @@ lv_obj_t * lv_line_create(lv_obj_t * par, lv_obj_t * copy) /*Create a basic object*/ lv_obj_t * new_line = lv_obj_create(par, copy); lv_mem_assert(new_line); + if(new_line == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_line); /*Extend the basic object to line object*/ lv_line_ext_t * ext = lv_obj_allocate_ext_attr(new_line, sizeof(lv_line_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->point_num = 0; ext->point_array = NULL; ext->auto_size = 1; diff --git a/lv_objx/lv_list.c b/lv_objx/lv_list.c index 9a4866c0d..4789c75c8 100644 --- a/lv_objx/lv_list.c +++ b/lv_objx/lv_list.c @@ -74,10 +74,13 @@ lv_obj_t * lv_list_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor basic object*/ lv_obj_t * new_list = lv_page_create(par, copy); lv_mem_assert(new_list); + if(new_list == NULL) return NULL; + if(ancestor_page_signal == NULL) ancestor_page_signal = lv_obj_get_signal_func(new_list); lv_list_ext_t * ext = lv_obj_allocate_ext_attr(new_list, sizeof(lv_list_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; ext->style_img = NULL; ext->styles_btn[LV_BTN_STATE_REL] = &lv_style_btn_rel; diff --git a/lv_objx/lv_lmeter.c b/lv_objx/lv_lmeter.c index adc5879f7..ec7956871 100644 --- a/lv_objx/lv_lmeter.c +++ b/lv_objx/lv_lmeter.c @@ -55,11 +55,14 @@ lv_obj_t * lv_lmeter_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of line meter*/ lv_obj_t * new_lmeter = lv_obj_create(par, copy); lv_mem_assert(new_lmeter); + if(new_lmeter== NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_lmeter); /*Allocate the line meter type specific extended data*/ lv_lmeter_ext_t * ext = lv_obj_allocate_ext_attr(new_lmeter, sizeof(lv_lmeter_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->min_value = 0; diff --git a/lv_objx/lv_mbox.c b/lv_objx/lv_mbox.c index 7ecd1f7fb..004e5c41f 100644 --- a/lv_objx/lv_mbox.c +++ b/lv_objx/lv_mbox.c @@ -63,11 +63,15 @@ lv_obj_t * lv_mbox_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor message box*/ lv_obj_t * new_mbox = lv_cont_create(par, copy); lv_mem_assert(new_mbox); + if(new_mbox == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_mbox); /*Allocate the message box type specific extended data*/ lv_mbox_ext_t * ext = lv_obj_allocate_ext_attr(new_mbox, sizeof(lv_mbox_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->text = NULL; ext->btnm = NULL; ext->anim_time = LV_MBOX_CLOSE_ANIM_TIME; diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 28e8aeae9..4dff3b2f0 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -60,12 +60,16 @@ lv_obj_t * lv_page_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor object*/ lv_obj_t * new_page = lv_cont_create(par, copy); lv_mem_assert(new_page); + if(new_page == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_page); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_page); /*Allocate the object type specific extended data*/ lv_page_ext_t * ext = lv_obj_allocate_ext_attr(new_page, sizeof(lv_page_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->scrl = NULL; ext->pr_action = NULL; ext->rel_action = NULL; diff --git a/lv_objx/lv_preload.c b/lv_objx/lv_preload.c index 78043b0a8..6df95c3a5 100644 --- a/lv_objx/lv_preload.c +++ b/lv_objx/lv_preload.c @@ -58,10 +58,13 @@ lv_obj_t * lv_preload_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of pre loader*/ lv_obj_t * new_preload = lv_arc_create(par, copy); lv_mem_assert(new_preload); + if(new_preload == NULL) return NULL; /*Allocate the pre loader type specific extended data*/ lv_preload_ext_t * ext = lv_obj_allocate_ext_attr(new_preload, sizeof(lv_preload_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_preload); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_preload); diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 4614c28ad..0ae8a179c 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -63,12 +63,15 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of roller*/ lv_obj_t * new_roller = lv_ddlist_create(par, copy); lv_mem_assert(new_roller); + if(new_roller == NULL) return NULL; + if(ancestor_scrl_signal == NULL) ancestor_scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_roller)); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_roller); /*Allocate the roller type specific extended data*/ lv_roller_ext_t * ext = lv_obj_allocate_ext_attr(new_roller, sizeof(lv_roller_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_roller, lv_roller_signal); diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index 5d907d0f8..835207a42 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -56,6 +56,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor slider*/ lv_obj_t * new_slider = lv_bar_create(par, copy); lv_mem_assert(new_slider); + if(new_slider == NULL) return NULL; if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_func(new_slider); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_slider); @@ -63,6 +64,7 @@ lv_obj_t * lv_slider_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the slider type specific extended data*/ lv_slider_ext_t * ext = lv_obj_allocate_ext_attr(new_slider, sizeof(lv_slider_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->action = NULL; diff --git a/lv_objx/lv_sw.c b/lv_objx/lv_sw.c index 48746d341..457986c99 100644 --- a/lv_objx/lv_sw.c +++ b/lv_objx/lv_sw.c @@ -53,12 +53,14 @@ lv_obj_t * lv_sw_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of switch*/ lv_obj_t * new_sw = lv_slider_create(par, copy); lv_mem_assert(new_sw); + if(new_sw == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_sw); /*Allocate the switch type specific extended data*/ lv_sw_ext_t * ext = lv_obj_allocate_ext_attr(new_sw, sizeof(lv_sw_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->changed = 0; diff --git a/lv_objx/lv_ta.c b/lv_objx/lv_ta.c index 51f0e14f1..9b6e54e73 100644 --- a/lv_objx/lv_ta.c +++ b/lv_objx/lv_ta.c @@ -77,6 +77,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor object*/ lv_obj_t * new_ta = lv_page_create(par, copy); lv_mem_assert(new_ta); + if(new_ta == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_ta); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_ta); if(scrl_signal == NULL) scrl_signal = lv_obj_get_signal_func(lv_page_get_scrl(new_ta)); @@ -85,6 +87,8 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, lv_obj_t * copy) /*Allocate the object type specific extended data*/ lv_ta_ext_t * ext = lv_obj_allocate_ext_attr(new_ta, sizeof(lv_ta_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->cursor.state = 0; ext->pwd_mode = 0; ext->pwd_tmp = NULL; @@ -185,6 +189,7 @@ void lv_ta_add_char(lv_obj_t * ta, char c) ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 2); /*+2: the new char + \0 */ lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp== NULL) return; lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, letter_buf); #if USE_LV_ANIMATION @@ -227,6 +232,7 @@ void lv_ta_add_text(lv_obj_t * ta, const char * txt) if(ext->pwd_mode != 0) { ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + strlen(txt) + 1); lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; lv_txt_ins(ext->pwd_tmp, ext->cursor.pos, txt); @@ -285,6 +291,7 @@ void lv_ta_del_char(lv_obj_t * ta) #endif ext->pwd_tmp = lv_mem_realloc(ext->pwd_tmp, strlen(ext->pwd_tmp) + 1); lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; } /*Move the cursor to the place of the deleted character*/ @@ -441,6 +448,9 @@ void lv_ta_set_pwd_mode(lv_obj_t * ta, bool pwd_en) char * txt = lv_label_get_text(ext->label); uint16_t len = strlen(txt); ext->pwd_tmp = lv_mem_alloc(len + 1); + lv_mem_assert(ext->pwd_tmp); + if(ext->pwd_tmp == NULL) return; + strcpy(ext->pwd_tmp, txt); uint16_t i; diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index ffd1dd496..23786c693 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -69,11 +69,13 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor of tab*/ lv_obj_t * new_tabview = lv_obj_create(par, copy); lv_mem_assert(new_tabview); + if(new_tabview == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_tabview); /*Allocate the tab type specific extended data*/ lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(new_tabview, sizeof(lv_tabview_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; /*Initialize the allocated 'ext' */ ext->drag_hor = 0; @@ -87,15 +89,19 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) ext->btns = NULL; ext->tab_load_action = NULL; ext->anim_time = LV_TABVIEW_ANIM_TIME; - ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); - ext->tab_name_ptr[0] = ""; - ext->tab_cnt = 0; + /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_tabview, lv_tabview_signal); /*Init the new tab tab*/ if(copy == NULL) { + ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); + lv_mem_assert(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; + ext->tab_name_ptr[0] = ""; + ext->tab_cnt = 0; + lv_obj_set_size(new_tabview, LV_HOR_RES, LV_VER_RES); ext->btns = lv_btnm_create(new_tabview, NULL); @@ -144,6 +150,8 @@ lv_obj_t * lv_tabview_create(lv_obj_t * par, lv_obj_t * copy) ext->tab_load_action = copy_ext->tab_load_action; ext->tab_name_ptr = lv_mem_alloc(sizeof(char *)); + lv_mem_assert(ext->tab_name_ptr); + if(ext->tab_name_ptr == NULL) return NULL; ext->tab_name_ptr[0] = ""; lv_btnm_set_map(ext->btns, ext->tab_name_ptr); @@ -205,9 +213,13 @@ lv_obj_t * lv_tabview_add_tab(lv_obj_t * tabview, const char * name) char * name_dm; if((name[0] & LV_BTNM_CTRL_MASK) == LV_BTNM_CTRL_CODE) { /*If control byte presented let is*/ name_dm = lv_mem_alloc(strlen(name) + 1); /*+1 for the the closing '\0' */ + lv_mem_assert(name_dm); + if(name_dm == NULL) return NULL; strcpy(name_dm, name); } else { /*Set a no long press control byte is not presented*/ name_dm = lv_mem_alloc(strlen(name) + 2); /*+1 for the the closing '\0' and +1 for the control byte */ + lv_mem_assert(name_dm); + if(name_dm == NULL) return NULL; name_dm[0] = '\221'; strcpy(&name_dm[1], name); } diff --git a/lv_objx/lv_win.c b/lv_objx/lv_win.c index 23546938c..b3ab5f166 100644 --- a/lv_objx/lv_win.c +++ b/lv_objx/lv_win.c @@ -49,11 +49,15 @@ lv_obj_t * lv_win_create(lv_obj_t * par, lv_obj_t * copy) /*Create the ancestor object*/ lv_obj_t * new_win = lv_obj_create(par, copy); lv_mem_assert(new_win); + if(new_win == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_win); /*Allocate the object type specific extended data*/ lv_win_ext_t * ext = lv_obj_allocate_ext_attr(new_win, sizeof(lv_win_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; + ext->page = NULL; ext->header = NULL; ext->title = NULL;