Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Feb 25, 2024
1 parent 324f59b commit fa007ea
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v17.0.6
hooks:
- id: clang-format
files: ^(src\/.+\.[ch]|tools\/matdump.c)$
files: ^(src\/.+\.[ch]|tools\/matdump.c|test\/test_mat.c)$
exclude: ^(src\/fortran\/matio_internal.c|src\/snprintf.c|src\/safe-math.h)$

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
5 changes: 1 addition & 4 deletions cmake/staticAnalyzers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(MATIO_ENABLE_CPPCHECK)
if(CPPCHECK)
set(CMAKE_C_CPPCHECK ${CPPCHECK}
--language=c
--quiet
--check-level=exhaustive
--suppress=checkersReport
--suppress=unusedFunction
Expand All @@ -11,11 +12,7 @@ if(MATIO_ENABLE_CPPCHECK)
--enable=all
--inline-suppr
--inconclusive
-i ${CMAKE_SOURCE_DIR}/test
-i ${CMAKE_SOURCE_DIR}/snprintf
-i ${CMAKE_SOURCE_DIR}/getopt
)
message(VERBOSE "Cppcheck finished setting up.")
else()
message(SEND_ERROR "Cppcheck requested but executable not found.")
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ WriteCompressedData(mat_t *mat, z_streamp z, void *data, int N, enum matio_types
z->next_out = buf;
z->avail_out = buf_size;
deflate(z, Z_NO_FLUSH);
/* // cppcheck-suppress uninitvar */
byteswritten += fwrite(buf, 1, buf_size - z->avail_out, (FILE *)mat->fp);
} while ( z->avail_out == 0 );

Expand Down Expand Up @@ -2299,6 +2300,7 @@ WriteCompressedTypeArrayFlags(mat_t *mat, matvar_t *matvar, z_streamp z)
z->next_out = ZLIB_BYTE_PTR(comp_buf);
z->avail_out = buf_size * sizeof(*comp_buf);
deflate(z, Z_NO_FLUSH);
/* // cppcheck-suppress uninitvar */
byteswritten +=
fwrite(comp_buf, 1, buf_size * sizeof(*comp_buf) - z->avail_out, (FILE *)mat->fp);
} while ( z->avail_out == 0 );
Expand Down Expand Up @@ -2540,6 +2542,7 @@ WriteCompressedCellArrayField(mat_t *mat, matvar_t *matvar, z_streamp z)
z->next_out = ZLIB_BYTE_PTR(comp_buf);
z->avail_out = buf_size * sizeof(*comp_buf);
deflate(z, Z_NO_FLUSH);
/* // cppcheck-suppress uninitvar */
byteswritten +=
fwrite(comp_buf, 1, buf_size * sizeof(*comp_buf) - z->avail_out, (FILE *)mat->fp);
} while ( z->avail_out == 0 );
Expand Down Expand Up @@ -2673,6 +2676,7 @@ WriteCompressedStructField(mat_t *mat, matvar_t *matvar, z_streamp z)
z->next_out = ZLIB_BYTE_PTR(comp_buf);
z->avail_out = buf_size * sizeof(*comp_buf);
deflate(z, Z_NO_FLUSH);
/* // cppcheck-suppress uninitvar */
byteswritten +=
fwrite(comp_buf, 1, buf_size * sizeof(*comp_buf) - z->avail_out, (FILE *)mat->fp);
} while ( z->avail_out == 0 );
Expand Down Expand Up @@ -5025,6 +5029,7 @@ Mat_VarWrite5(mat_t *mat, matvar_t *matvar, int compress)
z->next_out = ZLIB_BYTE_PTR(comp_buf);
z->avail_out = buf_size * sizeof(*comp_buf);
deflate(z, Z_NO_FLUSH);
/* // cppcheck-suppress uninitvar */
fwrite(comp_buf, 1, buf_size * sizeof(*comp_buf) - z->avail_out, (FILE *)mat->fp);
} while ( z->avail_out == 0 );
uncomp_buf[0] = array_flags_type;
Expand Down
32 changes: 17 additions & 15 deletions test/test_mat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,6 @@ test_write_empty_cell(const char *output_name)
mat = Mat_CreateVer(output_name, NULL, mat_file_ver);
if ( mat ) {
/* Write an empty cell */
matvar[0] = NULL;
dims[0] = 0;
dims[1] = 1;
cell_matvar = Mat_VarCreate("var1", MAT_C_CELL, MAT_T_CELL, 2, dims, NULL, 0);
Expand Down Expand Up @@ -2502,7 +2501,7 @@ test_struct_api_getfieldnames(void)
printf(" None\n");
} else {
for ( i = 0; i < nfields; i++ )
printf(" %3d. %s\n", i, fieldnames2[i]);
printf(" %3u. %s\n", i, fieldnames2[i]);
}
Mat_VarFree(matvar);

Expand All @@ -2514,7 +2513,7 @@ test_struct_api_getfieldnames(void)
printf(" None\n");
} else {
for ( i = 0; i < nfields; i++ )
printf(" %3d. %s\n", i, fieldnames2[i]);
printf(" %3u. %s\n", i, fieldnames2[i]);
}
Mat_VarFree(matvar);

Expand All @@ -2525,7 +2524,7 @@ test_struct_api_getfieldnames(void)
printf(" None\n");
} else {
for ( i = 0; i < nfields; i++ )
printf(" %3d. %s\n", i, fieldnames2[i]);
printf(" %3u. %s\n", i, fieldnames2[i]);
}

return err;
Expand All @@ -2535,7 +2534,7 @@ static int
test_struct_api_addfield(void)
{
size_t dims[2];
double data1[2] = {0, 1}, data2[3] = {2, 3, 4}, data3[3] = {5, 6, 7}, data4[2] = {8, 9};
const double data1[2] = {0, 1}, data2[3] = {2, 3, 4}, data3[3] = {5, 6, 7}, data4[2] = {8, 9};
matvar_t *fields[5], *matvar;

dims[0] = 2;
Expand Down Expand Up @@ -2863,7 +2862,8 @@ static int
test_get_struct_field(const char *file, const char *structname, const char *fieldname)
{
mat_t *mat;
matvar_t *matvar, *field;
matvar_t *matvar;
const matvar_t *field;
int index = 1, err = 0;

mat = Mat_Open(file, MAT_ACC_RDONLY);
Expand Down Expand Up @@ -2908,7 +2908,8 @@ test_get_struct_field(const char *file, const char *structname, const char *fiel
static int
test_readslab(const char *file, const char *var, enum matio_classes matvar_class)
{
int start[3] = {0, 0, 0}, stride[3] = {1, 1, 1}, edge[3] = {2, 2, 1}, err = 0;
const int start[3] = {0, 0, 0}, edge[3] = {2, 2, 1};
int stride[3] = {1, 1, 1}, err = 0;
mat_t *mat;
matvar_t *matvar;

Expand Down Expand Up @@ -3374,7 +3375,7 @@ static int
test_writenan(void)
{
int err = 0, i;
size_t dims[2] = {5, 5};
const size_t dims[2] = {5, 5};
double data[25] = {
0.0,
};
Expand Down Expand Up @@ -3405,7 +3406,7 @@ static int
test_writeinf(const char *output_name)
{
int err = 0, i;
size_t dims[2] = {5, 5};
const size_t dims[2] = {5, 5};
double data[25] = {
0.0,
};
Expand Down Expand Up @@ -3436,7 +3437,7 @@ static int
test_write_sparse(enum matio_classes matvar_class, const char *output_name)
{
int err = 0;
size_t dims[2] = {5, 10};
const size_t dims[2] = {5, 10};
mat_uint32_t ir[25] = {0, 4, 1, 2, 3, 0, 4, 1, 2, 3, 0, 4, 1,
2, 3, 0, 4, 1, 2, 3, 0, 4, 1, 2, 3};
mat_uint32_t jc[11] = {0, 2, 5, 7, 10, 12, 15, 17, 20, 22, 25};
Expand Down Expand Up @@ -3566,7 +3567,7 @@ static int
test_write_complex_sparse(enum matio_classes matvar_class, const char *output_name)
{
int err = 0;
size_t dims[2] = {5, 10};
const size_t dims[2] = {5, 10};
mat_uint32_t ir[25] = {0, 4, 1, 2, 3, 0, 4, 1, 2, 3, 0, 4, 1,
2, 3, 0, 4, 1, 2, 3, 0, 4, 1, 2, 3};
mat_uint32_t jc[11] = {0, 2, 5, 7, 10, 12, 15, 17, 20, 22, 25};
Expand Down Expand Up @@ -3738,7 +3739,7 @@ test_write_complex_sparse(enum matio_classes matvar_class, const char *output_na
}

static int
test_delete(char *file, char *name)
test_delete(char *file, const char *name)
{
int err = 0;
mat_t *mat;
Expand Down Expand Up @@ -4148,15 +4149,17 @@ main(int argc, char *argv[])
err += test_write_complex_sparse(matvar_class, output_name);
ntests++;
} else if ( !strcasecmp(argv[k], "ind2sub") ) {
size_t *subs, dims[3] = {256, 256, 124};
size_t *subs;
const size_t dims[3] = {256, 256, 124};
redirect_output(output_name);
subs = Mat_CalcSubscripts2(3, dims, 18921 - 1);
Mat_Message("(%zu,%zu,%zu)", subs[0], subs[1], subs[2]);
free(subs);
k++;
ntests++;
} else if ( !strcasecmp(argv[k], "sub2ind") ) {
size_t dims[3] = {256, 256, 124}, index[3] = {233, 74, 1};
const size_t dims[3] = {256, 256, 124};
const size_t index[3] = {233, 74, 1};
size_t linear_index = 0;
redirect_output(output_name);
err += Mat_CalcSingleSubscript2(3, dims, index, &linear_index);
Expand Down Expand Up @@ -4191,7 +4194,6 @@ main(int argc, char *argv[])
ntests++;
} else {
Mat_Critical("Unrecognized test %s", argv[k]);
k++;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/matdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ print_default_numeric_2d(const matvar_t *matvar)
printf("\n");
}
} else {
char *data = (char *)matvar->data;
const char *data = (char *)matvar->data;
for ( i = 0; i < matvar->dims[0]; i++ ) {
for ( j = 0; j < matvar->dims[1]; j++ ) {
size_t idx = matvar->dims[0] * j + i;
Expand Down

0 comments on commit fa007ea

Please sign in to comment.