From 155a47a5dd2e7ecabcb3e41c27f2702cc183ca89 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Wed, 2 Jan 2019 09:52:31 +0300 Subject: [PATCH] [F] Fixed incorrect error processing --- lib/fort.c | 2 ++ src/cell.c | 2 ++ tests/bb_tests/test_memory_errors.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/fort.c b/lib/fort.c index ba955dc..959a6e3 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -848,6 +848,8 @@ fort_cell_t *copy_cell(fort_cell_t *cell) assert(cell); fort_cell_t *result = create_cell(); + if (result == NULL) + return NULL; destroy_string_buffer(result->str_buffer); result->str_buffer = copy_string_buffer(cell->str_buffer); if (result->str_buffer == NULL) { diff --git a/src/cell.c b/src/cell.c index f9fd114..aeacd64 100644 --- a/src/cell.c +++ b/src/cell.c @@ -38,6 +38,8 @@ fort_cell_t *copy_cell(fort_cell_t *cell) assert(cell); fort_cell_t *result = create_cell(); + if (result == NULL) + return NULL; destroy_string_buffer(result->str_buffer); result->str_buffer = copy_string_buffer(cell->str_buffer); if (result->str_buffer == NULL) { diff --git a/tests/bb_tests/test_memory_errors.c b/tests/bb_tests/test_memory_errors.c index 43740b7..c8d725a 100644 --- a/tests/bb_tests/test_memory_errors.c +++ b/tests/bb_tests/test_memory_errors.c @@ -27,6 +27,7 @@ void test_free(void *ptr) static int create_table_and_show(void) { ft_table_t *table = NULL; + ft_table_t *table_copy = NULL; int result = 0; table = ft_create_table(); @@ -62,11 +63,17 @@ static int create_table_and_show(void) goto exit; } - const char *table_str = ft_to_string(table); - if (table_str == NULL) { + table_copy = ft_copy_table(table); + if (table_copy == NULL) { result = 8; goto exit; } + + const char *table_str = ft_to_string(table_copy); + if (table_str == NULL) { + result = 9; + goto exit; + } const char *table_str_etalon = "+---+---+-----+----------+\n" "| | | | |\n" @@ -87,13 +94,14 @@ static int create_table_and_show(void) "+---+---+-----+----------+\n"; /*assert_str_equal(table_str, table_str_etalon);*/ if (strcmp(table_str, table_str_etalon) != 0) { - result = 9; + result = 10; goto exit; } exit: ft_destroy_table(table); + ft_destroy_table(table_copy); return result; }