Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/mat73.c
Original file line number Diff line number Diff line change
Expand Up @@ -3319,6 +3319,16 @@ Mat_CalcDir73(mat_t *mat, size_t *n)
if ( NULL == mat || NULL == n )
return MATIO_E_BAD_ARGUMENT;

if ( mat->num_datasets == 0 ) {
Mat_Critical("Number of datasets is zero");
return MATIO_E_BAD_ARGUMENT;
}

if ( mat->fp == NULL ) {
Mat_Critical("Invalid file pointer");
return MATIO_E_BAD_ARGUMENT;
}

*n = 0;
mat->dir = (char **)calloc(mat->num_datasets, sizeof(char *));
if ( NULL == mat->dir ) {
Expand All @@ -3331,6 +3341,11 @@ Mat_CalcDir73(mat_t *mat, size_t *n)
ssize_t name_len = H5Lget_name_by_idx(*(hid_t *)mat->fp, "/", H5_INDEX_NAME, H5_ITER_INC, i,
NULL, 0, H5P_DEFAULT);
if ( name_len < 1 ) {
Mat_Critical("Invalid name length returned by H5Lget_name_by_idx");
for ( hsize_t j = 0; j < i; j++ ) {
free(mat->dir[j]);
}
free(mat->dir);
return MATIO_E_FAIL_TO_IDENTIFY;
}
name = (char *)malloc(name_len + 1);
Expand All @@ -3347,6 +3362,7 @@ Mat_CalcDir73(mat_t *mat, size_t *n)
(*n)++;
} else {
free(name);
free(name);
}
}
return MATIO_E_NO_ERROR;
Expand Down