1
0
Fork 0

[A] Added more cppcheck checks

This commit is contained in:
seleznevae 2018-11-18 11:11:39 +03:00
parent 39fcdf8e4e
commit 6fb83bc58f
6 changed files with 23 additions and 21 deletions

View File

@ -104,7 +104,7 @@ script:
# cppcheck run # cppcheck run
- | - |
if [ "${FORT_C_COMPILER}" = "gcc-8" ]; then if [ "${FORT_C_COMPILER}" = "gcc-8" ]; then
cppcheck lib cppcheck --enable=warning,style,performance,portability,information,missingInclude --error-exitcode=1 lib
fi fi
# Print all environment variables to aid in CI development # Print all environment variables to aid in CI development

View File

@ -3491,7 +3491,7 @@ fort_table_properties_t *copy_table_properties(const fort_table_properties_t *pr
destroy_vector(new_opt->cell_properties); destroy_vector(new_opt->cell_properties);
new_opt->cell_properties = copy_cell_properties(properties->cell_properties); new_opt->cell_properties = copy_cell_properties(properties->cell_properties);
if (new_opt == NULL) { if (new_opt->cell_properties == NULL) {
destroy_table_properties(new_opt); destroy_table_properties(new_opt);
return NULL; return NULL;
} }
@ -3512,12 +3512,13 @@ fort_table_properties_t *copy_table_properties(const fort_table_properties_t *pr
Begin of file "row.c" Begin of file "row.c"
********************************************************/ ********************************************************/
#include <assert.h>
#include <ctype.h>
/* #include "row.h" */ /* Commented by amalgamation script */ /* #include "row.h" */ /* Commented by amalgamation script */
/* #include "cell.h" */ /* Commented by amalgamation script */ /* #include "cell.h" */ /* Commented by amalgamation script */
/* #include "string_buffer.h" */ /* Commented by amalgamation script */ /* #include "string_buffer.h" */ /* Commented by amalgamation script */
#include "assert.h"
/* #include "vector.h" */ /* Commented by amalgamation script */ /* #include "vector.h" */ /* Commented by amalgamation script */
#include "ctype.h"
struct fort_row { struct fort_row {
vector_t *cells; vector_t *cells;
@ -3547,13 +3548,12 @@ fort_row_t *create_row(void)
FT_INTERNAL FT_INTERNAL
void destroy_row(fort_row_t *row) void destroy_row(fort_row_t *row)
{ {
size_t i = 0;
if (row == NULL) if (row == NULL)
return; return;
if (row->cells) { if (row->cells) {
size_t cells_n = vector_size(row->cells); size_t cells_n = vector_size(row->cells);
for (i = 0; i < cells_n; ++i) { for (size_t i = 0; i < cells_n; ++i) {
fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i);
destroy_cell(cell); destroy_cell(cell);
} }
@ -4957,8 +4957,8 @@ size_t buffer_text_width(string_buffer_t *buffer)
max_length = MAX(max_length, (size_t)(end - beg)); max_length = MAX(max_length, (size_t)(end - beg));
++n; ++n;
} }
} else {
#ifdef FT_HAVE_WCHAR #ifdef FT_HAVE_WCHAR
} else {
while (1) { while (1) {
const wchar_t *beg = NULL; const wchar_t *beg = NULL;
const wchar_t *end = NULL; const wchar_t *end = NULL;
@ -5794,12 +5794,11 @@ struct interval {
static int bisearch(wchar_t ucs, const struct interval *table, int max) static int bisearch(wchar_t ucs, const struct interval *table, int max)
{ {
int min = 0; int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last) if (ucs < table[0].first || ucs > table[max].last)
return 0; return 0;
while (max >= min) { while (max >= min) {
mid = (min + max) / 2; int mid = (min + max) / 2;
if (ucs > table[mid].last) if (ucs > table[mid].last)
min = mid + 1; min = mid + 1;
else if (ucs < table[mid].first) else if (ucs < table[mid].first)
@ -5932,13 +5931,15 @@ static int mk_wcwidth(wchar_t ucs)
FT_INTERNAL FT_INTERNAL
int mk_wcswidth(const wchar_t *pwcs, size_t n) int mk_wcswidth(const wchar_t *pwcs, size_t n)
{ {
int w, width = 0; int width = 0;
for (; *pwcs && n-- > 0; pwcs++) for (; *pwcs && n-- > 0; pwcs++) {
int w;
if ((w = mk_wcwidth(*pwcs)) < 0) if ((w = mk_wcwidth(*pwcs)) < 0)
return -1; return -1;
else else
width += w; width += w;
}
return width; return width;
} }

View File

@ -1009,7 +1009,7 @@ fort_table_properties_t *copy_table_properties(const fort_table_properties_t *pr
destroy_vector(new_opt->cell_properties); destroy_vector(new_opt->cell_properties);
new_opt->cell_properties = copy_cell_properties(properties->cell_properties); new_opt->cell_properties = copy_cell_properties(properties->cell_properties);
if (new_opt == NULL) { if (new_opt->cell_properties == NULL) {
destroy_table_properties(new_opt); destroy_table_properties(new_opt);
return NULL; return NULL;
} }

View File

@ -1,9 +1,10 @@
#include <assert.h>
#include <ctype.h>
#include "row.h" #include "row.h"
#include "cell.h" #include "cell.h"
#include "string_buffer.h" #include "string_buffer.h"
#include "assert.h"
#include "vector.h" #include "vector.h"
#include "ctype.h"
struct fort_row { struct fort_row {
vector_t *cells; vector_t *cells;
@ -33,13 +34,12 @@ fort_row_t *create_row(void)
FT_INTERNAL FT_INTERNAL
void destroy_row(fort_row_t *row) void destroy_row(fort_row_t *row)
{ {
size_t i = 0;
if (row == NULL) if (row == NULL)
return; return;
if (row->cells) { if (row->cells) {
size_t cells_n = vector_size(row->cells); size_t cells_n = vector_size(row->cells);
for (i = 0; i < cells_n; ++i) { for (size_t i = 0; i < cells_n; ++i) {
fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i); fort_cell_t *cell = *(fort_cell_t **)vector_at(row->cells, i);
destroy_cell(cell); destroy_cell(cell);
} }

View File

@ -319,8 +319,8 @@ size_t buffer_text_width(string_buffer_t *buffer)
max_length = MAX(max_length, (size_t)(end - beg)); max_length = MAX(max_length, (size_t)(end - beg));
++n; ++n;
} }
} else {
#ifdef FT_HAVE_WCHAR #ifdef FT_HAVE_WCHAR
} else {
while (1) { while (1) {
const wchar_t *beg = NULL; const wchar_t *beg = NULL;
const wchar_t *end = NULL; const wchar_t *end = NULL;

View File

@ -73,12 +73,11 @@ struct interval {
static int bisearch(wchar_t ucs, const struct interval *table, int max) static int bisearch(wchar_t ucs, const struct interval *table, int max)
{ {
int min = 0; int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last) if (ucs < table[0].first || ucs > table[max].last)
return 0; return 0;
while (max >= min) { while (max >= min) {
mid = (min + max) / 2; int mid = (min + max) / 2;
if (ucs > table[mid].last) if (ucs > table[mid].last)
min = mid + 1; min = mid + 1;
else if (ucs < table[mid].first) else if (ucs < table[mid].first)
@ -211,13 +210,15 @@ static int mk_wcwidth(wchar_t ucs)
FT_INTERNAL FT_INTERNAL
int mk_wcswidth(const wchar_t *pwcs, size_t n) int mk_wcswidth(const wchar_t *pwcs, size_t n)
{ {
int w, width = 0; int width = 0;
for (; *pwcs && n-- > 0; pwcs++) for (; *pwcs && n-- > 0; pwcs++) {
int w;
if ((w = mk_wcwidth(*pwcs)) < 0) if ((w = mk_wcwidth(*pwcs)) < 0)
return -1; return -1;
else else
width += w; width += w;
}
return width; return width;
} }