diff --git a/src/mat.c b/src/mat.c index 601abfc2..390ce5d2 100644 --- a/src/mat.c +++ b/src/mat.c @@ -2465,7 +2465,8 @@ Mat_VarPrint(const matvar_t *matvar, int printdata) * @retval 0 on success */ int -Mat_VarReadData(mat_t *mat, matvar_t *matvar, void *data, int *start, int *stride, int *edge) +Mat_VarReadData(mat_t *mat, matvar_t *matvar, void *data, const int *start, const int *stride, + const int *edge) { int err = MATIO_E_NO_ERROR; @@ -2842,7 +2843,7 @@ Mat_VarReadNextPredicate(mat_t *mat, mat_iter_pred_t pred, const void *user_data * @see Mat_VarWrite/Mat_VarWriteAppend */ int -Mat_VarWriteInfo(mat_t *mat, matvar_t *matvar) +Mat_VarWriteInfo(const mat_t *mat, matvar_t *matvar) { Mat_Critical( "Mat_VarWriteInfo/Mat_VarWriteData is not supported. " @@ -2867,8 +2868,8 @@ Mat_VarWriteInfo(mat_t *mat, matvar_t *matvar) * @see Mat_VarWrite/Mat_VarWriteAppend */ int -Mat_VarWriteData(mat_t *mat, matvar_t *matvar, void *data, const int *start, const int *stride, - const int *edge) +Mat_VarWriteData(const mat_t *mat, matvar_t *matvar, void *data, const int *start, + const int *stride, const int *edge) { Mat_Critical( "Mat_VarWriteInfo/Mat_VarWriteData is not supported. " diff --git a/src/mat4.c b/src/mat4.c index 583294a8..9aee2a33 100644 --- a/src/mat4.c +++ b/src/mat4.c @@ -56,7 +56,7 @@ mat_t * Mat_Create4(const char *matname) { - FILE *fp = NULL; + FILE *fp; mat_t *mat = NULL; #if defined(_WIN32) @@ -64,6 +64,8 @@ Mat_Create4(const char *matname) if ( NULL != wname ) { fp = _wfopen(wname, L"w+b"); free(wname); + } else { + fp = NULL; } #else fp = fopen(matname, "w+b"); @@ -119,7 +121,6 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar) mat_int32_t namelen; } Fmatrix; - mat_uint32_t i; Fmatrix x; if ( NULL == mat || NULL == matvar ) @@ -200,9 +201,7 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar) fwrite(&x, sizeof(Fmatrix), 1, (FILE *)mat->fp); fwrite(matvar->name, sizeof(char), x.namelen, (FILE *)mat->fp); if ( matvar->isComplex ) { - mat_complex_split_t *complex_data; - - complex_data = (mat_complex_split_t *)matvar->data; + const mat_complex_split_t *complex_data = (mat_complex_split_t *)matvar->data; fwrite(complex_data->Re, matvar->data_size, nelems, (FILE *)mat->fp); fwrite(complex_data->Im, matvar->data_size, nelems, (FILE *)mat->fp); } else { @@ -213,7 +212,7 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar) case MAT_C_SPARSE: { mat_sparse_t *sparse; double tmp; - mat_uint32_t j; + mat_uint32_t i, j; size_t stride = Mat_SizeOf(matvar->data_type); #if !defined(EXTENDED_SPARSE) if ( MAT_T_DOUBLE != matvar->data_type ) @@ -247,12 +246,9 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar) fwrite(&tmp, sizeof(double), 1, (FILE *)mat->fp); tmp = 0.; if ( matvar->isComplex ) { - mat_complex_split_t *complex_data; - char *re, *im; - - complex_data = (mat_complex_split_t *)sparse->data; - re = (char *)complex_data->Re; - im = (char *)complex_data->Im; + mat_complex_split_t *complex_data = (mat_complex_split_t *)sparse->data; + const char *re = (char *)complex_data->Re; + const char *im = (char *)complex_data->Im; for ( i = 0; i < sparse->njc - 1; i++ ) { for ( j = sparse->jc[i]; j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) { fwrite(re + j * stride, stride, 1, (FILE *)mat->fp); @@ -265,7 +261,7 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar) } } } else { - char *data = (char *)sparse->data; + const char *data = (char *)sparse->data; for ( i = 0; i < sparse->njc - 1; i++ ) { for ( j = sparse->jc[i]; j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) { fwrite(data + j * stride, stride, 1, (FILE *)mat->fp); @@ -768,8 +764,8 @@ Mat_VarRead4(mat_t *mat, matvar_t *matvar) * @endif */ int -Mat_VarReadData4(mat_t *mat, matvar_t *matvar, void *data, const int *start, const int *stride, - const int *edge) +Mat_VarReadData4(mat_t *mat, const matvar_t *matvar, void *data, const int *start, + const int *stride, const int *edge) { int err = MATIO_E_NO_ERROR; diff --git a/src/mat4.h b/src/mat4.h index 7455bcf5..1e81b41a 100644 --- a/src/mat4.h +++ b/src/mat4.h @@ -38,7 +38,7 @@ EXTERN mat_t *Mat_Create4(const char *matname); EXTERN int Mat_VarWrite4(mat_t *mat, const matvar_t *matvar); EXTERN int Mat_VarRead4(mat_t *mat, matvar_t *matvar); -EXTERN int Mat_VarReadData4(mat_t *mat, matvar_t *matvar, void *data, const int *start, +EXTERN int Mat_VarReadData4(mat_t *mat, const matvar_t *matvar, void *data, const int *start, const int *stride, const int *edge); EXTERN int Mat_VarReadDataLinear4(mat_t *mat, matvar_t *matvar, void *data, int start, int stride, int edge); diff --git a/src/mat5.c b/src/mat5.c index 801e8012..3130a900 100644 --- a/src/mat5.c +++ b/src/mat5.c @@ -479,12 +479,12 @@ ReadSparse(mat_t *mat, const matvar_t *matvar, mat_uint32_t *n, mat_uint32_t **v { int data_in_tag = 0; enum matio_types packed_type; - mat_uint32_t tag[2] = {0, 0}; size_t bytesread = 0; mat_uint32_t N = 0; if ( matvar->compression == MAT_COMPRESSION_ZLIB ) { #if HAVE_ZLIB + mat_uint32_t tag[2] = {0, 0}; matvar->internal->z->avail_in = 0; if ( 0 != Inflate(mat, matvar->internal->z, tag, 4, &bytesread) ) { return bytesread; @@ -501,6 +501,7 @@ ReadSparse(mat_t *mat, const matvar_t *matvar, mat_uint32_t *n, mat_uint32_t **v } #endif } else { + mat_uint32_t tag[2] = {0, 0}; if ( 0 != Read(tag, 4, 1, (FILE *)mat->fp, &bytesread) ) { return bytesread; } @@ -524,9 +525,8 @@ ReadSparse(mat_t *mat, const matvar_t *matvar, mat_uint32_t *n, mat_uint32_t **v *n = N / 4; *v = (mat_uint32_t *)calloc(N, 1); if ( NULL != *v ) { - int nBytes; if ( matvar->compression == MAT_COMPRESSION_NONE ) { - nBytes = ReadUInt32Data(mat, *v, packed_type, *n); + int nBytes = ReadUInt32Data(mat, *v, packed_type, *n); /* * If the data was in the tag we started on a 4-byte * boundary so add 4 to make it an 8-byte @@ -538,7 +538,7 @@ ReadSparse(mat_t *mat, const matvar_t *matvar, mat_uint32_t *n, mat_uint32_t **v (void)fseeko((FILE *)mat->fp, 8 - (nBytes % 8), SEEK_CUR); #if HAVE_ZLIB } else if ( matvar->compression == MAT_COMPRESSION_ZLIB ) { - nBytes = ReadCompressedUInt32Data(mat, matvar->internal->z, *v, packed_type, *n); + int nBytes = ReadCompressedUInt32Data(mat, matvar->internal->z, *v, packed_type, *n); /* * If the data was in the tag we started on a 4-byte * boundary so add 4 to make it an 8-byte @@ -629,7 +629,7 @@ GetMatrixMaxBufSize(matvar_t *matvar, size_t *size) mat_t * Mat_Create5(const char *matname, const char *hdr_str) { - FILE *fp = NULL; + FILE *fp; mat_int16_t endian = 0, version; mat_t *mat = NULL; size_t err; @@ -640,6 +640,8 @@ Mat_Create5(const char *matname, const char *hdr_str) if ( NULL != wname ) { fp = _wfopen(wname, L"w+b"); free(wname); + } else { + fp = NULL; } #else fp = fopen(matname, "w+b"); @@ -984,7 +986,7 @@ WriteCompressedData(mat_t *mat, z_streamp z, void *data, int N, enum matio_types static size_t ReadNextCell(mat_t *mat, matvar_t *matvar) { - size_t bytesread = 0, i; + size_t bytesread = 0; int err; matvar_t **cells = NULL; size_t nelems = 1; @@ -1011,6 +1013,7 @@ ReadNextCell(mat_t *mat, matvar_t *matvar) if ( matvar->compression == MAT_COMPRESSION_ZLIB ) { #if HAVE_ZLIB + size_t i; mat_uint32_t uncomp_buf[16]; mat_uint32_t nBytes; mat_uint32_t array_flags; @@ -1233,6 +1236,7 @@ ReadNextCell(mat_t *mat, matvar_t *matvar) #endif } else { + size_t i; mat_uint32_t buf[6] = {0, 0, 0, 0, 0, 0}; mat_uint32_t nBytes; mat_uint32_t array_flags; @@ -1375,9 +1379,8 @@ ReadNextCell(mat_t *mat, matvar_t *matvar) static size_t ReadNextStructField(mat_t *mat, matvar_t *matvar) { - mat_uint32_t fieldname_size; int err; - size_t bytesread = 0, nfields, i; + size_t bytesread = 0; matvar_t **fields = NULL; size_t nelems = 1, nelems_x_nfields; @@ -1388,6 +1391,7 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar) } if ( matvar->compression == MAT_COMPRESSION_ZLIB ) { #if HAVE_ZLIB + size_t nfields, i mat_uint32_t fieldname_size; mat_uint32_t uncomp_buf[16]; mat_uint32_t array_flags, len; @@ -1662,6 +1666,8 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar) Mat_Critical("Not compiled with zlib support"); #endif } else { + size_t nfields, i; + mat_uint32_t fieldname_size; mat_uint32_t buf[6] = {0, 0, 0, 0, 0, 0}; mat_uint32_t array_flags, len; @@ -4888,7 +4894,7 @@ Mat_VarWrite5(mat_t *mat, matvar_t *matvar, int compress) int array_flags_type = MAT_T_UINT32, dims_array_type = MAT_T_INT32; int array_flags_size = 8, matrix_type = MAT_T_MATRIX; const mat_uint32_t pad4 = 0; - int nBytes, i, nzmax = 0; + int nBytes, nzmax = 0; mat_off_t start = 0, end = 0; if ( NULL == mat ) @@ -4905,6 +4911,7 @@ Mat_VarWrite5(mat_t *mat, matvar_t *matvar, int compress) #else { #endif + int i; fwrite(&matrix_type, 4, 1, (FILE *)mat->fp); fwrite(&pad4, 4, 1, (FILE *)mat->fp); start = ftello((FILE *)mat->fp); @@ -5146,7 +5153,7 @@ matvar_t * Mat_VarReadNextInfo5(mat_t *mat) { int err; - mat_uint32_t data_type, array_flags, nBytes; + mat_uint32_t data_type, nBytes; mat_off_t fpos; matvar_t *matvar = NULL; @@ -5397,7 +5404,7 @@ Mat_VarReadNextInfo5(mat_t *mat) /* Array flags */ if ( buf[0] == MAT_T_UINT32 || buf[0] == MAT_T_INT32 ) { /* Also allow INT32 for SWAN */ - array_flags = buf[2]; + mat_uint32_t array_flags = buf[2]; matvar->class_type = CLASS_FROM_ARRAY_FLAGS(array_flags); matvar->isComplex = (array_flags & MAT_F_COMPLEX); matvar->isGlobal = (array_flags & MAT_F_GLOBAL); diff --git a/src/matio.h b/src/matio.h index 06d877eb..8a805258 100644 --- a/src/matio.h +++ b/src/matio.h @@ -331,8 +331,8 @@ EXTERN matvar_t *Mat_VarGetStructsLinear(const matvar_t *matvar, int start, int int copy_fields); EXTERN void Mat_VarPrint(const matvar_t *matvar, int printdata); EXTERN matvar_t *Mat_VarRead(mat_t *mat, const char *name); -EXTERN int Mat_VarReadData(mat_t *mat, matvar_t *matvar, void *data, int *start, int *stride, - int *edge); +EXTERN int Mat_VarReadData(mat_t *mat, matvar_t *matvar, void *data, const int *start, + const int *stride, const int *edge); EXTERN int Mat_VarReadDataAll(mat_t *mat, matvar_t *matvar); EXTERN int Mat_VarReadDataLinear(mat_t *mat, matvar_t *matvar, void *data, int start, int stride, int edge); @@ -350,8 +350,8 @@ EXTERN matvar_t *Mat_VarSetStructFieldByName(matvar_t *matvar, const char *field EXTERN int Mat_VarWrite(mat_t *mat, matvar_t *matvar, enum matio_compression compress); EXTERN int Mat_VarWriteAppend(mat_t *mat, matvar_t *matvar, enum matio_compression compress, int dim); -EXTERN int Mat_VarWriteInfo(mat_t *mat, matvar_t *matvar); -EXTERN int Mat_VarWriteData(mat_t *mat, matvar_t *matvar, void *data, const int *start, +EXTERN int Mat_VarWriteInfo(const mat_t *mat, matvar_t *matvar); +EXTERN int Mat_VarWriteData(const mat_t *mat, matvar_t *matvar, void *data, const int *start, const int *stride, const int *edge); /* Other functions */ diff --git a/test/test_snprintf.c b/test/test_snprintf.c index 704bd9d9..818da896 100644 --- a/test/test_snprintf.c +++ b/test/test_snprintf.c @@ -15,7 +15,7 @@ int main(int argc, char **argv) { char buf1[1024]; char buf2[1024]; - char *fp_fmt[] = { + const char *fp_fmt[] = { "%1.1f", "%-1.5f", "%1.5f", @@ -33,10 +33,10 @@ int main(int argc, char **argv) "-16.16f", NULL }; - double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, + const double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, 0.9996, 1.996, 4.136, 5.030201, 0.00205, /* END LIST */ 0}; - char *int_fmt[] = { + const char *int_fmt[] = { "%-1.5d", "%1.5d", "%123.9d", @@ -49,8 +49,8 @@ int main(int argc, char **argv) "%d", NULL }; - long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; - char *str_fmt[] = { + const long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; + const char *str_fmt[] = { "10.5s", "5.10s", "10.1s", @@ -63,7 +63,7 @@ int main(int argc, char **argv) "%10s", NULL }; - char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; + const char *str_vals[] = {"hello", "a", "", "a longer string", NULL}; int x, y; int fail = 0; int num = 0;