table: add asserts after allocations

This commit is contained in:
Gabor Kiss-Vamosi
2020-03-24 19:38:57 +01:00
parent bb0c5a968c
commit b40c5ada05

View File

@@ -170,6 +170,7 @@ void lv_table_set_cell_value(lv_obj_t * table, uint16_t row, uint16_t col, const
ext->cell_data[cell] = lv_mem_realloc(ext->cell_data[cell], strlen(txt) + 2); /*+1: trailing '\0; +1: format byte*/ ext->cell_data[cell] = lv_mem_realloc(ext->cell_data[cell], strlen(txt) + 2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]); LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return; if(ext->cell_data[cell] == NULL) return;
strcpy(ext->cell_data[cell] + 1, txt); /*+1 to skip the format byte*/ strcpy(ext->cell_data[cell] + 1, txt); /*+1 to skip the format byte*/
ext->cell_data[cell][0] = format.format_byte; ext->cell_data[cell][0] = format.format_byte;
@@ -191,6 +192,8 @@ void lv_table_set_row_cnt(lv_obj_t * table, uint16_t row_cnt)
if(ext->row_cnt > 0 && ext->col_cnt > 0) { if(ext->row_cnt > 0 && ext->col_cnt > 0) {
ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *)); ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *));
LV_ASSERT_MEM(ext->cell_data);
if(ext->cell_data == NULL) return;
/*Initilize the new fields*/ /*Initilize the new fields*/
if(old_row_cnt < row_cnt) { if(old_row_cnt < row_cnt) {
@@ -227,6 +230,9 @@ void lv_table_set_col_cnt(lv_obj_t * table, uint16_t col_cnt)
if(ext->row_cnt > 0 && ext->col_cnt > 0) { if(ext->row_cnt > 0 && ext->col_cnt > 0) {
ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *)); ext->cell_data = lv_mem_realloc(ext->cell_data, ext->row_cnt * ext->col_cnt * sizeof(char *));
LV_ASSERT_MEM(ext->cell_data);
if(ext->cell_data == NULL) return;
/*Initilize the new fields*/ /*Initilize the new fields*/
if(old_col_cnt < col_cnt) { if(old_col_cnt < col_cnt) {
uint16_t old_cell_cnt = old_col_cnt * ext->row_cnt; uint16_t old_cell_cnt = old_col_cnt * ext->row_cnt;
@@ -287,6 +293,9 @@ void lv_table_set_cell_align(lv_obj_t * table, uint16_t row, uint16_t col, lv_la
if(ext->cell_data[cell] == NULL) { if(ext->cell_data[cell] == NULL) {
ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return;
ext->cell_data[cell][0] = 0; ext->cell_data[cell][0] = 0;
ext->cell_data[cell][1] = '\0'; ext->cell_data[cell][1] = '\0';
} }
@@ -323,6 +332,9 @@ void lv_table_set_cell_type(lv_obj_t * table, uint16_t row, uint16_t col, uint8_
if(ext->cell_data[cell] == NULL) { if(ext->cell_data[cell] == NULL) {
ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return;
ext->cell_data[cell][0] = 0; ext->cell_data[cell][0] = 0;
ext->cell_data[cell][1] = '\0'; ext->cell_data[cell][1] = '\0';
} }
@@ -364,6 +376,9 @@ void lv_table_set_cell_crop(lv_obj_t * table, uint16_t row, uint16_t col, bool c
if(ext->cell_data[cell] == NULL) { if(ext->cell_data[cell] == NULL) {
ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return;
ext->cell_data[cell][0] = 0; ext->cell_data[cell][0] = 0;
ext->cell_data[cell][1] = '\0'; ext->cell_data[cell][1] = '\0';
} }
@@ -400,6 +415,9 @@ void lv_table_set_cell_merge_right(lv_obj_t * table, uint16_t row, uint16_t col,
if(ext->cell_data[cell] == NULL) { if(ext->cell_data[cell] == NULL) {
ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ ext->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/
LV_ASSERT_MEM(ext->cell_data[cell]);
if(ext->cell_data[cell] == NULL) return;
ext->cell_data[cell][0] = 0; ext->cell_data[cell][0] = 0;
ext->cell_data[cell][1] = '\0'; ext->cell_data[cell][1] = '\0';
} }