Skip to content

Commit

Permalink
Do not allocate dummy data
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed May 27, 2024
1 parent c9cbf89 commit 08dcf9b
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar)
} else {
Mat_Critical("Couldn't determine file position");
}
if ( fields[i]->internal->data != NULL ||
if ( fields[i]->internal->data != NULL || nBytes <= (1 << MAX_WBITS) ||
fields[i]->class_type == MAT_C_STRUCT ||
fields[i]->class_type == MAT_C_CELL ) {
/* Memory optimization: Free inflate state */
Expand Down Expand Up @@ -3085,10 +3085,10 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)

if ( matvar == NULL )
return MATIO_E_BAD_ARGUMENT;
else if ( matvar->rank == 0 ) /* An empty data set */
if ( matvar->rank == 0 || matvar->nbytes == 0 ) /* An empty data set */
return MATIO_E_NO_ERROR;
#if HAVE_ZLIB
else if ( NULL != matvar->internal->data ) {
if ( NULL != matvar->internal->data ) {
/* Data already read in ReadNextStructField or ReadNextCell */
matvar->data = matvar->internal->data;
matvar->internal->data = NULL;
Expand Down Expand Up @@ -3229,18 +3229,14 @@ Mat_VarRead5(mat_t *mat, matvar_t *matvar)
break;
}
if ( 0 == matvar->nbytes ) {
matvar->data = calloc(1, 1);
} else {
matvar->data = calloc(matvar->nbytes, 1);
break;
}
matvar->data = calloc(matvar->nbytes, 1);
if ( NULL == matvar->data ) {
err = MATIO_E_OUT_OF_MEMORY;
Mat_Critical("Couldn't allocate memory for the data");
break;
}
if ( 0 == matvar->nbytes ) {
break;
}
{
size_t nbytes = 0;
err = Mul(&nbytes, nelems, matvar->data_size);
Expand Down

0 comments on commit 08dcf9b

Please sign in to comment.