[A] Added more checks

This commit is contained in:
seleznevae 2018-03-29 22:18:49 +03:00
parent 58d7062c0f
commit 7b16e1aec1
5 changed files with 107 additions and 65 deletions

View File

@ -21,8 +21,11 @@ static FTABLE *create_basic_table()
return table; return table;
} }
int main() int main(int argc, char *argv[])
{ {
(void)argc;
(void)argv;
FTABLE *table = NULL; FTABLE *table = NULL;
table = ft_create_table(); table = ft_create_table();

View File

@ -114,23 +114,37 @@ int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const
if (row >= hint_height_cell(cell, context) if (row >= hint_height_cell(cell, context)
|| row < cell_padding_top || row < cell_padding_top
|| row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) {
int k = snprint_n_chars_(buf, buf_len, buf_len - 1, space_char); return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char);
return k; }
} else {
int written = 0;
#define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \
if (k < 0) {\
goto clear; \
} \
dev += k; \
} while(0)
int dev = 0;
int k = 0;
int left = cell_padding_left; int left = cell_padding_left;
int right = cell_padding_right; int right = cell_padding_right;
written += snprint_n_chars_(buf + written, buf_len - written, left, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, left, space_char));
if (cell->str_buffer) if (cell->str_buffer)
written += buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + written, buf_len - written - right, context); CHECK_RESULT_AND_MOVE_DEV(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + dev, buf_len - dev - right, context));
else else
written += snprint_n_chars_(buf + written, buf_len - written, buf_len - written - right, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, buf_len - dev - right, space_char));
written += snprint_n_chars_(buf + written, buf_len - written, right, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, right, space_char));
return written; return dev;
}
clear:
return -1;
#undef CHECK_RESULT_AND_MOVE_DEV
} }
int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, const context_t *context) int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, const context_t *context)
@ -152,23 +166,36 @@ int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, co
if (row >= hint_height_cell(cell, context) if (row >= hint_height_cell(cell, context)
|| row < cell_padding_top || row < cell_padding_top
|| row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) { || row >= (cell_padding_top + buffer_text_height(cell->str_buffer))) {
int k = snprint_n_chars_(buf, buf_len, buf_len - 1, space_char); return snprint_n_chars_(buf, buf_len, buf_len - 1, space_char);
return k; }
} else {
int written = 0; #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \
if (k < 0) {\
goto clear; \
} \
dev += k; \
} while(0)
int dev = 0;
int k = 0;
int left = cell_padding_left; int left = cell_padding_left;
int right = cell_padding_right; int right = cell_padding_right;
written += snprint_n_chars_(buf + written, buf_len - written, left, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, left, space_char));
if (cell->str_buffer) if (cell->str_buffer)
written += buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + written, buf_len - written - right, context); CHECK_RESULT_AND_MOVE_DEV(buffer_printf_(cell->str_buffer, row - cell_padding_top, buf + dev, buf_len - dev - right, context));
else else
written += snprint_n_chars_(buf + written, buf_len - written, buf_len - written - right, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, buf_len - dev - right, space_char));
written += snprint_n_chars_(buf + written, buf_len - written, right, space_char); CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buf + dev, buf_len - dev, right, space_char));
return written; return dev;
}
clear:
return -1;
#undef CHECK_RESULT_AND_MOVE_DEV
} }

View File

@ -462,11 +462,13 @@ int ft_table_write_ln(FTABLE *FT_RESTRICT table, size_t rows, size_t cols, const
const char* ft_to_string(const FTABLE *FT_RESTRICT table) const char* ft_to_string(const FTABLE *FT_RESTRICT table)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef char char_type; typedef char char_type;
const char_type *empty_string = ""; const char_type *empty_string = "";
@ -572,11 +574,13 @@ clear:
const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table) const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef wchar_t char_type; typedef wchar_t char_type;
const char_type *empty_string = L""; const char_type *empty_string = L"";

View File

@ -118,11 +118,13 @@ int print_row_separator(char *buffer, size_t buffer_sz,
const separator_t *sep, const context_t *context) const separator_t *sep, const context_t *context)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef char char_type; typedef char char_type;
char new_line_char = '\n'; char new_line_char = '\n';
@ -232,11 +234,13 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
const context_t *context) const context_t *context)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef wchar_t char_type; typedef wchar_t char_type;
char new_line_char = L'\n'; char new_line_char = L'\n';
@ -473,11 +477,13 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
size_t row_height, const context_t *context) size_t row_height, const context_t *context)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef char char_type; typedef char char_type;
char space_char = ' '; char space_char = ' ';
@ -551,11 +557,13 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
size_t row_height, const context_t *context) size_t row_height, const context_t *context)
{ {
#define CHECK_RESULT_AND_MOVE_DEV(statement) \ #define CHECK_RESULT_AND_MOVE_DEV(statement) \
do { \
k = statement; \ k = statement; \
if (k < 0) {\ if (k < 0) {\
goto clear; \ goto clear; \
} \ } \
dev += k; dev += k; \
} while(0)
typedef wchar_t char_type; typedef wchar_t char_type;
char space_char = L' '; char space_char = L' ';

View File

@ -18,7 +18,7 @@ void test_vector_basic(void)
WHEN("Pushing less items than initial capacity") { WHEN("Pushing less items than initial capacity") {
for (i = 0; i < init_capacity; ++i) { for (i = 0; i < init_capacity; ++i) {
item_t item = i; item_t item = (item_t)i;
vector_push(vector, &item); vector_push(vector, &item);
} }
@ -38,7 +38,7 @@ void test_vector_basic(void)
WHEN("Pushing more items than initial capacity") { WHEN("Pushing more items than initial capacity") {
for (i = 0; i < 2 * init_capacity; ++i) { for (i = 0; i < 2 * init_capacity; ++i) {
item_t item = 2 * i; item_t item = (item_t)(2 * i);
vector_push(vector, &item); vector_push(vector, &item);
} }