From 88a5d764540d1cf54fd5f94ec1bd81fc224427e5 Mon Sep 17 00:00:00 2001 From: seleznevae Date: Sat, 17 Nov 2018 10:44:35 +0300 Subject: [PATCH] [A] Added more warnings to compilation --- CMakeLists.txt | 15 +++++++++++++-- lib/fort.c | 41 ++++++++++++++++++----------------------- lib/fort.h | 40 ++++++++++++++++++++-------------------- src/fort_impl.c | 28 ++++++++++++++-------------- src/fort_utils.c | 8 ++++---- 5 files changed, 69 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8996144..522dee4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,8 +52,19 @@ if("${FORT_COMPILER}" STREQUAL "MSVC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W4") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W4") else("${FORT_COMPILER}" STREQUAL "MSVC") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -Wextra -Werror -std=c99 -Wpedantic") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Wextra -Werror -std=c++11") + set(ADDITIONAL_WARNINGS "\ + -Wduplicated-cond \ + -Wlogical-op \ + -Wdouble-promotion \ + -Wshadow \ + -Wformat=2 \ + -Wno-variadic-macros \ + -Wcast-align \ + ") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -Wextra -Werror -std=c99 -Wpedantic ${ADDITIONAL_WARNINGS}") + + set(ADDITIONAL_WARNINGS "${ADDITIONAL_WARNINGS} -Wuseless-cast ") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g -Wextra -Werror -std=c++11 ${ADDITIONAL_WARNINGS}") endif("${FORT_COMPILER}" STREQUAL "MSVC") diff --git a/lib/fort.c b/lib/fort.c index c5f66e4..c46d22b 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -1272,22 +1272,17 @@ static fort_status_t set_cell_property_impl(fort_cell_props_t *opt, uint32_t pro } else if (PROP_IS_SET(property, FT_CPROP_CELL_BG_COLOR)) { opt->cell_bg_color_number = value; } else if (PROP_IS_SET(property, FT_CPROP_CELL_TEXT_STYLE)) { -// opt->cell_text_style = value; enum ft_text_style v = (enum ft_text_style)value; if (v == FT_TSTYLE_DEFAULT) { opt->cell_text_style = FT_TSTYLE_DEFAULT; } else { -// opt->cell_text_style &= ~((unsigned)FT_TSTYLE_DEFAULT); opt->cell_text_style |= v; } } else if (PROP_IS_SET(property, FT_CPROP_CONT_TEXT_STYLE)) { -// opt->content_text_style = value; - enum ft_text_style v = (enum ft_text_style)value; if (v == FT_TSTYLE_DEFAULT) { opt->content_text_style = v; } else { - // opt->cell_text_style &= ~((unsigned)FT_TSTYLE_DEFAULT); opt->content_text_style |= v; } } @@ -2990,20 +2985,20 @@ struct ft_border_style *FT_FRAME_STYLE = (struct ft_border_style *) &FORT_FRAME static void set_border_props_for_props(fort_table_properties_t *properties, const struct ft_border_style *style) { - if ((struct fort_border_style *)style == &FORT_BASIC_STYLE - || (struct fort_border_style *)style == &FORT_BASIC2_STYLE - || (struct fort_border_style *)style == &FORT_SIMPLE_STYLE - || (struct fort_border_style *)style == &FORT_DOT_STYLE - || (struct fort_border_style *)style == &FORT_PLAIN_STYLE - || (struct fort_border_style *)style == &FORT_EMPTY_STYLE - || (struct fort_border_style *)style == &FORT_SOLID_STYLE - || (struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE - || (struct fort_border_style *)style == &FORT_NICE_STYLE - || (struct fort_border_style *)style == &FORT_DOUBLE_STYLE - || (struct fort_border_style *)style == &FORT_DOUBLE2_STYLE - || (struct fort_border_style *)style == &FORT_BOLD_STYLE - || (struct fort_border_style *)style == &FORT_BOLD2_STYLE - || (struct fort_border_style *)style == &FORT_FRAME_STYLE) { + if ((const struct fort_border_style *)style == &FORT_BASIC_STYLE + || (const struct fort_border_style *)style == &FORT_BASIC2_STYLE + || (const struct fort_border_style *)style == &FORT_SIMPLE_STYLE + || (const struct fort_border_style *)style == &FORT_DOT_STYLE + || (const struct fort_border_style *)style == &FORT_PLAIN_STYLE + || (const struct fort_border_style *)style == &FORT_EMPTY_STYLE + || (const struct fort_border_style *)style == &FORT_SOLID_STYLE + || (const struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE + || (const struct fort_border_style *)style == &FORT_NICE_STYLE + || (const struct fort_border_style *)style == &FORT_DOUBLE_STYLE + || (const struct fort_border_style *)style == &FORT_DOUBLE2_STYLE + || (const struct fort_border_style *)style == &FORT_BOLD_STYLE + || (const struct fort_border_style *)style == &FORT_BOLD2_STYLE + || (const struct fort_border_style *)style == &FORT_FRAME_STYLE) { memcpy(&(properties->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style)); return; } @@ -4239,13 +4234,13 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str) else { wchar_t wcs[WCS_SIZE]; const char *ptr = str; - size_t length; - length = mbsrtowcs(wcs, (const char **)&ptr, WCS_SIZE, NULL); + size_t wcs_len; + wcs_len = mbsrtowcs(wcs, (const char **)&ptr, WCS_SIZE, NULL); /* for simplicity */ - if ((length == (size_t) - 1) || length > 1) { + if ((wcs_len == (size_t) - 1) || wcs_len > 1) { return -1; } else { - wcs[length] = L'\0'; + wcs[wcs_len] = L'\0'; size_t k = n; while (k) { *buf = *wcs; diff --git a/lib/fort.h b/lib/fort.h index 28bb74a..2d6c608 100644 --- a/lib/fort.h +++ b/lib/fort.h @@ -693,27 +693,27 @@ int ft_set_border_style(ft_table_t *table, const struct ft_border_style *style); /** - * @name Colors. - * @{ + * Colors. */ -#define FT_COLOR_DEFAULT 0 -#define FT_COLOR_BLACK 1 -#define FT_COLOR_RED 2 -#define FT_COLOR_GREEN 3 -#define FT_COLOR_YELLOW 4 -#define FT_COLOR_BLUE 5 -#define FT_COLOR_MAGENTA 6 -#define FT_COLOR_CYAN 7 -#define FT_COLOR_LIGHT_GRAY 8 -#define FT_COLOR_DARK_GRAY 9 -#define FT_COLOR_LIGHT_RED 10 -#define FT_COLOR_LIGHT_GREEN 11 -#define FT_COLOR_LIGHT_YELLOW 12 -#define FT_COLOR_LIGHT_BLUE 13 -#define FT_COLOR_LIGHT_MAGENTA 15 -#define FT_COLOR_LIGHT_CYAN 16 -#define FT_COLOR_LIGHT_WHYTE 17 -/** @} */ +enum ft_color { + FT_COLOR_DEFAULT = 0, + FT_COLOR_BLACK = 1, + FT_COLOR_RED = 2, + FT_COLOR_GREEN = 3, + FT_COLOR_YELLOW = 4, + FT_COLOR_BLUE = 5, + FT_COLOR_MAGENTA = 6, + FT_COLOR_CYAN = 7, + FT_COLOR_LIGHT_GRAY = 8, + FT_COLOR_DARK_GRAY = 9, + FT_COLOR_LIGHT_RED = 10, + FT_COLOR_LIGHT_GREEN = 11, + FT_COLOR_LIGHT_YELLOW = 12, + FT_COLOR_LIGHT_BLUE = 13, + FT_COLOR_LIGHT_MAGENTA = 15, + FT_COLOR_LIGHT_CYAN = 16, + FT_COLOR_LIGHT_WHYTE = 17 +}; /** * Text styles. diff --git a/src/fort_impl.c b/src/fort_impl.c index d47c5fe..2e31c3e 100644 --- a/src/fort_impl.c +++ b/src/fort_impl.c @@ -847,20 +847,20 @@ struct ft_border_style *FT_FRAME_STYLE = (struct ft_border_style *) &FORT_FRAME static void set_border_props_for_props(fort_table_properties_t *properties, const struct ft_border_style *style) { - if ((struct fort_border_style *)style == &FORT_BASIC_STYLE - || (struct fort_border_style *)style == &FORT_BASIC2_STYLE - || (struct fort_border_style *)style == &FORT_SIMPLE_STYLE - || (struct fort_border_style *)style == &FORT_DOT_STYLE - || (struct fort_border_style *)style == &FORT_PLAIN_STYLE - || (struct fort_border_style *)style == &FORT_EMPTY_STYLE - || (struct fort_border_style *)style == &FORT_SOLID_STYLE - || (struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE - || (struct fort_border_style *)style == &FORT_NICE_STYLE - || (struct fort_border_style *)style == &FORT_DOUBLE_STYLE - || (struct fort_border_style *)style == &FORT_DOUBLE2_STYLE - || (struct fort_border_style *)style == &FORT_BOLD_STYLE - || (struct fort_border_style *)style == &FORT_BOLD2_STYLE - || (struct fort_border_style *)style == &FORT_FRAME_STYLE) { + if ((const struct fort_border_style *)style == &FORT_BASIC_STYLE + || (const struct fort_border_style *)style == &FORT_BASIC2_STYLE + || (const struct fort_border_style *)style == &FORT_SIMPLE_STYLE + || (const struct fort_border_style *)style == &FORT_DOT_STYLE + || (const struct fort_border_style *)style == &FORT_PLAIN_STYLE + || (const struct fort_border_style *)style == &FORT_EMPTY_STYLE + || (const struct fort_border_style *)style == &FORT_SOLID_STYLE + || (const struct fort_border_style *)style == &FORT_SOLID_ROUND_STYLE + || (const struct fort_border_style *)style == &FORT_NICE_STYLE + || (const struct fort_border_style *)style == &FORT_DOUBLE_STYLE + || (const struct fort_border_style *)style == &FORT_DOUBLE2_STYLE + || (const struct fort_border_style *)style == &FORT_BOLD_STYLE + || (const struct fort_border_style *)style == &FORT_BOLD2_STYLE + || (const struct fort_border_style *)style == &FORT_FRAME_STYLE) { memcpy(&(properties->border_style), (struct fort_border_style *)style, sizeof(struct fort_border_style)); return; } diff --git a/src/fort_utils.c b/src/fort_utils.c index a48b26f..7629c18 100644 --- a/src/fort_utils.c +++ b/src/fort_utils.c @@ -260,13 +260,13 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str) else { wchar_t wcs[WCS_SIZE]; const char *ptr = str; - size_t length; - length = mbsrtowcs(wcs, (const char **)&ptr, WCS_SIZE, NULL); + size_t wcs_len; + wcs_len = mbsrtowcs(wcs, (const char **)&ptr, WCS_SIZE, NULL); /* for simplicity */ - if ((length == (size_t) - 1) || length > 1) { + if ((wcs_len == (size_t) - 1) || wcs_len > 1) { return -1; } else { - wcs[length] = L'\0'; + wcs[wcs_len] = L'\0'; size_t k = n; while (k) { *buf = *wcs;