1
0
Fork 0

[F] Fixed compiler warnings

This commit is contained in:
seleznevae 2018-04-16 22:33:05 +03:00
parent 72dbe85b7f
commit 4e2f21fb05
8 changed files with 61 additions and 35 deletions

View File

@ -36,7 +36,7 @@ void destroy_cell(fort_cell_t *cell)
F_FREE(cell);
}
int hint_width_cell(const fort_cell_t *cell, const context_t *context)
unsigned int hint_width_cell(const fort_cell_t *cell, const context_t *context)
{
/* todo:
* At the moment min width includes paddings. Maybe it is better that min width weren't include
@ -45,23 +45,23 @@ int hint_width_cell(const fort_cell_t *cell, const context_t *context)
assert(cell);
assert(context);
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
int result = cell_padding_left + cell_padding_right;
unsigned int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
unsigned int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
unsigned int result = cell_padding_left + cell_padding_right;
if (cell->str_buffer && cell->str_buffer->str.data) {
result += buffer_text_width(cell->str_buffer);
}
result = MAX(result, get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_MIN_WIDTH));
result = MAX(result, (unsigned)get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_MIN_WIDTH));
return result;
}
int hint_height_cell(const fort_cell_t *cell, const context_t *context)
unsigned int hint_height_cell(const fort_cell_t *cell, const context_t *context)
{
assert(cell);
assert(context);
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
int cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_BOTTOM_PADDING);
int cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_EMPTY_STR_HEIGHT);
unsigned int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
unsigned int cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_BOTTOM_PADDING);
unsigned int cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_EMPTY_STR_HEIGHT);
int result = cell_padding_top + cell_padding_bottom;
if (cell->str_buffer && cell->str_buffer->str.data) {
size_t text_height = buffer_text_height(cell->str_buffer);
@ -105,9 +105,9 @@ int cell_printf(fort_cell_t *cell, size_t row, char *buf, size_t buf_len, const
return -1;
}
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
unsigned int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
unsigned int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
unsigned int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
if (row >= hint_height_cell(cell, context)
|| row < cell_padding_top
@ -147,9 +147,9 @@ int cell_wprintf(fort_cell_t *cell, size_t row, wchar_t *buf, size_t buf_len, co
return -1;
}
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
unsigned int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
unsigned int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
unsigned int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
if (row >= hint_height_cell(cell, context)
|| row < cell_padding_top

View File

@ -13,8 +13,8 @@ fort_cell_t * create_cell(void);
void destroy_cell(fort_cell_t *cell);
int hint_width_cell(const fort_cell_t *cell, const context_t *context);
int hint_height_cell(const fort_cell_t *cell, const context_t *context);
unsigned int hint_width_cell(const fort_cell_t *cell, const context_t *context);
unsigned int hint_height_cell(const fort_cell_t *cell, const context_t *context);
/*

View File

@ -127,4 +127,8 @@ int wsnprint_n_chars(wchar_t *buf, size_t length, size_t n, wchar_t ch);
written += tmp; \
} while(0)
#define CHECK_NOT_NEGATIVE(x) \
do { if (x < 0) goto fort_fail; } while (0)
#endif /* FORT_IMPL_H */

View File

@ -156,24 +156,33 @@ static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t opt
OPTION_SET(opt->options, option);
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
CHECK_NOT_NEGATIVE(value);
opt->col_min_width = value;
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
opt->align = (enum ft_text_alignment)value;
} else if (OPTION_IS_SET(option, FT_COPT_TOP_PADDING)) {
CHECK_NOT_NEGATIVE(value);
opt->cell_padding_top = value;
} else if (OPTION_IS_SET(option, FT_COPT_BOTTOM_PADDING)) {
CHECK_NOT_NEGATIVE(value);
opt->cell_padding_bottom = value;
} else if (OPTION_IS_SET(option, FT_COPT_LEFT_PADDING)) {
CHECK_NOT_NEGATIVE(value);
opt->cell_padding_left = value;
} else if (OPTION_IS_SET(option, FT_COPT_RIGHT_PADDING)) {
CHECK_NOT_NEGATIVE(value);
opt->cell_padding_right = value;
} else if (OPTION_IS_SET(option, FT_COPT_EMPTY_STR_HEIGHT)) {
CHECK_NOT_NEGATIVE(value);
opt->cell_empty_string_height = value;
} else if (OPTION_IS_SET(option, FT_COPT_ROW_TYPE)) {
opt->row_type = (enum ft_row_type)value;
}
return FT_SUCCESS;
fort_fail:
return FT_EINVAL;
}
@ -329,6 +338,7 @@ fort_entire_table_options_t g_entire_table_options = {
static fort_status_t set_entire_table_option_internal(fort_entire_table_options_t *options, uint32_t option, int value)
{
assert(options);
CHECK_NOT_NEGATIVE(value);
if (OPTION_IS_SET(option, FT_TOPT_LEFT_MARGIN)) {
options->left_margin = value;
} else if (OPTION_IS_SET(option, FT_TOPT_TOP_MARGIN)) {
@ -341,6 +351,9 @@ static fort_status_t set_entire_table_option_internal(fort_entire_table_options_
return FT_EINVAL;
}
return FT_SUCCESS;
fort_fail:
return FT_EINVAL;
}
fort_status_t set_entire_table_option(fort_table_options_t *table_options, uint32_t option, int value)
@ -361,6 +374,13 @@ fort_table_options_t g_table_options = {
/* border_style */
BASIC_STYLE,
NULL, /* cell_options */
/* entire_table_options */
{
0, /* left_margin */
0, /* top_margin */
0, /* right_margin */
0 /* bottom_margin */
}
};

View File

@ -29,13 +29,13 @@ struct fort_cell_options
unsigned cell_row;
unsigned cell_col;
uint32_t options;
int col_min_width;
unsigned int col_min_width;
enum ft_text_alignment align;
int cell_padding_top;
int cell_padding_bottom;
int cell_padding_left;
int cell_padding_right;
int cell_empty_string_height;
unsigned int cell_padding_top;
unsigned int cell_padding_bottom;
unsigned int cell_padding_left;
unsigned int cell_padding_right;
unsigned int cell_empty_string_height;
enum ft_row_type row_type;
};
@ -125,10 +125,10 @@ extern struct fort_border_style FORT_EMPTY_STYLE;
struct fort_entire_table_options
{
int left_margin;
int top_margin;
int right_margin;
int bottom_margin;
unsigned int left_margin;
unsigned int top_margin;
unsigned int right_margin;
unsigned int bottom_margin;
};
typedef struct fort_entire_table_options fort_entire_table_options_t;
extern fort_entire_table_options_t g_entire_table_options;

View File

@ -52,7 +52,7 @@ void destroy_row(fort_row_t *row)
int columns_in_row(const fort_row_t *row)
unsigned int columns_in_row(const fort_row_t *row)
{
if (row == NULL || row->cells == NULL)
return 0;
@ -324,7 +324,7 @@ fort_row_t *create_row_from_string(const char *str)
{
char *pos = NULL;
char *base_pos = NULL;
int number_of_separators = 0;
unsigned int number_of_separators = 0;
fort_row_t *row = create_row();
if (row == NULL)
@ -417,11 +417,11 @@ fort_row_t *create_row_from_fmt_string(const char *fmt, va_list *va_args)
int virtual_sz = vsnprintf(buffer->str.cstr, string_buffer_capacity(buffer)/*buffer->str_sz*/, fmt, va);
va_end(va);
/* If error encountered */
if (virtual_sz == -1)
if (virtual_sz < 0)
goto clear;
/* Successful write */
if (virtual_sz < string_buffer_capacity(buffer))
if ((size_t)virtual_sz < string_buffer_capacity(buffer))
break;
/* Otherwise buffer was too small, so incr. buffer size ant try again. */
@ -463,7 +463,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
if (row == NULL)
return -1;
int cols_in_row = columns_in_row(row);
unsigned int cols_in_row = columns_in_row(row);
if (cols_in_row > col_width_arr_sz)
return -1;
@ -533,7 +533,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
if (row == NULL)
return -1;
int cols_in_row = columns_in_row(row);
unsigned int cols_in_row = columns_in_row(row);
if (cols_in_row > col_width_arr_sz)
return -1;

View File

@ -24,7 +24,7 @@ fort_row_t * create_row_from_string(const char *str);
fort_row_t* create_row_from_fmt_string(const char* fmt, va_list *va_args);
int columns_in_row(const fort_row_t *row);
unsigned int columns_in_row(const fort_row_t *row);
fort_cell_t *get_cell_implementation(fort_row_t *row, size_t col, enum PolicyOnNull policy);
fort_cell_t *get_cell(fort_row_t *row, size_t col);

View File

@ -260,7 +260,9 @@ size_t buffer_text_width(string_buffer_t *buffer)
return max_length;
int line_width = mk_wcswidth(beg, end - beg);
max_length = MAX(max_length, line_width);
if (line_width < 0) /* For safety */
line_width = 0;
max_length = MAX(max_length, (size_t)line_width);
++n;
}