Skip to content

Commit

Permalink
Check inputs
Browse files Browse the repository at this point in the history
As reported by Coverity Scan
  • Loading branch information
tbeu committed Jul 22, 2024
1 parent f07ede8 commit f177329
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/mat4.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ Mat_VarWrite4(mat_t *mat, const matvar_t *matvar)

if ( NULL == mat || NULL == matvar )
return MATIO_E_BAD_ARGUMENT;
if ( NULL == matvar->name || matvar->rank != 2 )
if ( NULL == matvar->name || matvar->rank != 2 || NULL == matvar->data )
return MATIO_E_OUTPUT_BAD_DATA;
if ( matvar->class_type == MAT_C_SPARSE ) {
const mat_sparse_t *sparse = (const mat_sparse_t *)matvar->data;
if ( sparse->njc == 0 )
return MATIO_E_OUTPUT_BAD_DATA;
}

switch ( matvar->data_type ) {
case MAT_T_DOUBLE:
Expand Down
7 changes: 3 additions & 4 deletions src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -4903,15 +4903,14 @@ Mat_VarWrite5(mat_t *mat, matvar_t *matvar, int compress)
int nBytes, nzmax = 0;
mat_off_t start = 0, end = 0;

if ( NULL == mat )
if ( NULL == mat || NULL == matvar )
return MATIO_E_BAD_ARGUMENT;
if ( NULL == matvar->name || NULL == matvar->data )
return MATIO_E_OUTPUT_BAD_DATA;

/* FIXME: SEEK_END is not Guaranteed by the C standard */
(void)fseeko((FILE *)mat->fp, 0, SEEK_END); /* Always write at end of file */

if ( NULL == matvar || NULL == matvar->name )
return MATIO_E_BAD_ARGUMENT;

#if HAVE_ZLIB
if ( compress == MAT_COMPRESSION_NONE ) {
#else
Expand Down
2 changes: 2 additions & 0 deletions src/mat73.c
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,8 @@ Mat_VarWrite73(mat_t *mat, matvar_t *matvar, int compress)

if ( NULL == mat || NULL == matvar )
return MATIO_E_BAD_ARGUMENT;
if ( NULL == matvar->name || NULL == matvar->data )
return MATIO_E_OUTPUT_BAD_DATA;

matvar->compression = (enum matio_compression)compress;

Expand Down

0 comments on commit f177329

Please sign in to comment.