diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..c2475f5 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,42 @@ +--- +# Configure clang-tidy for this project. + +# Disabled: +# -google-readability-namespace-comments the BIGTABLE_CLIENT_NS is a macro, and +# clang-tidy fails to match it against the initial value. +Checks: >- + bugprone-*, + #google-readability-*, + misc-*, + modernize-*, + #readability-identifier-naming, + #readability-*, + performance-*, + -google-readability-namespace-comments, + -readability-named-parameter + +# Enable most warnings as errors. +WarningsAsErrors: >- + bugprone-*, + clang-*, + google-*, + misc-*, + modernize-*, + #readability-identifier-naming, + #readability-*, + performance-* + +#CheckOptions: +# - { key: readability-identifier-naming.NamespaceCase, value: lower_case } +# - { key: readability-identifier-naming.ClassCase, value: lower_case } +# - { key: readability-identifier-naming.StructCase, value: lower_case } +# - { key: readability-identifier-naming.TemplateParameterCase, value: lower_case } +# - { key: readability-identifier-naming.FunctionCase, value: lower_case } +# - { key: readability-identifier-naming.VariableCase, value: lower_case } +# - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } +# - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } +# - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } +# - { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE } +# - { key: readability-identifier-naming.ConstexprVariableCase, value: UPPER_CASE } +# - { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE } +# - { key: readability-identifier-naming.MemberConstantCase, value: UPPER_CASE } diff --git a/.travis.yml b/.travis.yml index 96d0bfb..f3ef9ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,13 @@ matrix: os: linux sudo: required # to prevent fail of executables build with clang and sanitizers compiler: clang - env: CC=clang + env: + - CC=clang + - BASIC_LINUX_CLANG=yes + addons: + apt: + sources: ['llvm-toolchain-trusty-4.0'] + packages: ['clang-tidy-4.0'] # Linux / GCC - name: "Linux gcc-4.9" @@ -142,6 +148,15 @@ script: cppcheck --std=c++11 --enable=warning,style,performance,portability,information,missingInclude --error-exitcode=1 lib fi + # clang-tidy run + - | + if [ "${BASIC_LINUX_CLANG}" = "yes" ]; then + # don't know how force warnings of clang-tidy to be errors + cp .clang-tidy lib + clang-tidy -dump-config lib/fort.c + fi + + # doxygen run - | if [ "${BASIC_LINUX_GCC}" = "yes" ]; then diff --git a/lib/fort.c b/lib/fort.c index 9fb16c8..a4ed127 100644 --- a/lib/fort.c +++ b/lib/fort.c @@ -74,8 +74,8 @@ SOFTWARE. #define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1)) -#define MAX(a,b) ((a) > (b) ? (a) : b) -#define MIN(a,b) ((a) < (b) ? (a) : b) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) enum PolicyOnNull { @@ -208,7 +208,7 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str); #define CHECK_NOT_NEGATIVE(x) \ - do { if (x < 0) goto fort_fail; } while (0) + do { if ((x) < 0) goto fort_fail; } while (0) #endif /* FORT_IMPL_H */ @@ -253,13 +253,14 @@ void *vector_at(vector_t *, size_t index); FT_INTERNAL fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos); - +/* #define FOR_EACH_(type, item, vector, index_name) \ size_t index_name = 0; \ for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name) #define FOR_EACH(type, item, vector) \ FOR_EACH_(type, item, vector, UNIQUE_NAME(i)) +*/ #ifdef FT_TEST_BUILD @@ -392,7 +393,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, wchar_t *buf, siz #define PROP_IS_SET(ft_props, property) ((ft_props) & (property)) #define PROP_SET(ft_props, property) ((ft_props) |=(property)) -#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)property)) +#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)(property))) #define TEXT_STYLE_TAG_MAX_SIZE 64 @@ -3407,12 +3408,10 @@ size_t max_border_elem_strlen(struct fort_table_properties *properties) result = MAX(result, strlen(properties->border_style.border_chars[i])); } - i = 0; for (i = 0; i < BorderItemPosSize; ++i) { result = MAX(result, strlen(properties->border_style.header_border_chars[i])); } - i = 0; for (i = 0; i < SepratorItemPosSize; ++i) { result = MAX(result, strlen(properties->border_style.separator_chars[i])); } @@ -5312,6 +5311,7 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col *cols = 0; if (table && table->rows) { *rows = vector_size(table->rows); + /* fort_row_t *row = NULL; FOR_EACH(fort_row_t *, row, table->rows) { (void)i0; @@ -5319,6 +5319,13 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col if (cols_in_row > *cols) *cols = cols_in_row; } + */ + for (size_t row_index = 0; row_index < vector_size(table->rows); ++row_index) { + fort_row_t *row = *(fort_row_t**)vector_at(table->rows, row_index); + size_t cols_in_row = columns_in_row(row); + if (cols_in_row > *cols) + *cols = cols_in_row; + } } return FT_SUCCESS; } @@ -5380,7 +5387,6 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table, } if (combined_cells_found) { - col = 0; for (col = 0; col < cols; ++col) { size_t row = 0; for (row = 0; row < rows; ++row) { diff --git a/src/fort_utils.h b/src/fort_utils.h index 5218560..f1a2692 100644 --- a/src/fort_utils.h +++ b/src/fort_utils.h @@ -37,8 +37,8 @@ #define F_CREATE(type) ((type *)F_CALLOC(sizeof(type), 1)) -#define MAX(a,b) ((a) > (b) ? (a) : b) -#define MIN(a,b) ((a) < (b) ? (a) : b) +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) enum PolicyOnNull { @@ -171,6 +171,6 @@ int wsnprint_n_string(wchar_t *buf, size_t length, size_t n, const char *str); #define CHECK_NOT_NEGATIVE(x) \ - do { if (x < 0) goto fort_fail; } while (0) + do { if ((x) < 0) goto fort_fail; } while (0) #endif /* FORT_IMPL_H */ diff --git a/src/properties.c b/src/properties.c index 4ce331f..7aa28d4 100644 --- a/src/properties.c +++ b/src/properties.c @@ -955,12 +955,10 @@ size_t max_border_elem_strlen(struct fort_table_properties *properties) result = MAX(result, strlen(properties->border_style.border_chars[i])); } - i = 0; for (i = 0; i < BorderItemPosSize; ++i) { result = MAX(result, strlen(properties->border_style.header_border_chars[i])); } - i = 0; for (i = 0; i < SepratorItemPosSize; ++i) { result = MAX(result, strlen(properties->border_style.separator_chars[i])); } diff --git a/src/properties.h b/src/properties.h index 453bbdb..2a76d88 100644 --- a/src/properties.h +++ b/src/properties.h @@ -7,7 +7,7 @@ #define PROP_IS_SET(ft_props, property) ((ft_props) & (property)) #define PROP_SET(ft_props, property) ((ft_props) |=(property)) -#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)property)) +#define PROP_UNSET(ft_props, property) ((ft_props) &= ~((uint32_t)(property))) #define TEXT_STYLE_TAG_MAX_SIZE 64 diff --git a/src/row.c b/src/row.c index 66958a4..0537651 100644 --- a/src/row.c +++ b/src/row.c @@ -612,7 +612,7 @@ fort_row_t *create_row_from_string(const char *str) char_type *pos = NULL; char_type *base_pos = NULL; - unsigned int number_of_separators = 0; + size_t number_of_separators = 0; fort_row_t *row = create_row(); if (row == NULL) @@ -701,7 +701,7 @@ fort_row_t *create_row_from_wstring(const wchar_t *str) char_type *pos = NULL; char_type *base_pos = NULL; - unsigned int number_of_separators = 0; + size_t number_of_separators = 0; fort_row_t *row = create_row(); if (row == NULL) diff --git a/src/table.c b/src/table.c index f847e6f..69c6f4b 100644 --- a/src/table.c +++ b/src/table.c @@ -108,6 +108,7 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col *cols = 0; if (table && table->rows) { *rows = vector_size(table->rows); + /* fort_row_t *row = NULL; FOR_EACH(fort_row_t *, row, table->rows) { (void)i0; @@ -115,6 +116,13 @@ fort_status_t get_table_sizes(const ft_table_t *table, size_t *rows, size_t *col if (cols_in_row > *cols) *cols = cols_in_row; } + */ + for (size_t row_index = 0; row_index < vector_size(table->rows); ++row_index) { + fort_row_t *row = *(fort_row_t**)vector_at(table->rows, row_index); + size_t cols_in_row = columns_in_row(row); + if (cols_in_row > *cols) + *cols = cols_in_row; + } } return FT_SUCCESS; } @@ -176,7 +184,6 @@ fort_status_t table_rows_and_cols_geometry(const ft_table_t *table, } if (combined_cells_found) { - col = 0; for (col = 0; col < cols; ++col) { size_t row = 0; for (row = 0; row < rows; ++row) { diff --git a/src/vector.h b/src/vector.h index a350284..9d1d684 100644 --- a/src/vector.h +++ b/src/vector.h @@ -30,13 +30,14 @@ void *vector_at(vector_t *, size_t index); FT_INTERNAL fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos); - +/* #define FOR_EACH_(type, item, vector, index_name) \ size_t index_name = 0; \ for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name) #define FOR_EACH(type, item, vector) \ FOR_EACH_(type, item, vector, UNIQUE_NAME(i)) +*/ #ifdef FT_TEST_BUILD