Skip to content

Commit

Permalink
Fix illegal memory access
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Jul 23, 2024
1 parent 1e5c40e commit a148eec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/mat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2230,12 +2230,14 @@ Mat_VarPrint(const matvar_t *matvar, int printdata)
int err = Mul(&nelems_x_nfields, nelems, nfields);
if ( MATIO_E_NO_ERROR == err && nelems_x_nfields > 0 ) {
printf("Fields[%" SIZE_T_FMTSTR "] {\n", nelems_x_nfields);
for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( NULL == fields[i] ) {
printf(" Name: %s\n Rank: %d\n",
matvar->internal->fieldnames[i % nfields], 0);
} else {
Mat_VarPrint(fields[i], printdata);
if ( NULL != matvar->internal->fieldnames ) {
for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( NULL == fields[i] ) {
printf(" Name: %s\n Rank: %d\n",
matvar->internal->fieldnames[i % nfields], 0);
} else {
Mat_VarPrint(fields[i], printdata);
}
}
}
printf("}\n");
Expand Down
2 changes: 1 addition & 1 deletion src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar)
if ( NULL != ptr ) {
err = Inflate(mat, matvar->internal->z, ptr,
(unsigned int)(nfields * fieldname_size + i), &bytesread);
if ( 0 == err ) {
if ( MATIO_E_NO_ERROR == err ) {
SetFieldNames(matvar, ptr, nfields, fieldname_size);
} else {
matvar->internal->num_fields = nfields;
Expand Down

0 comments on commit a148eec

Please sign in to comment.