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 Oct 19, 2024
1 parent eb937e7 commit 915d657
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/mat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ 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);
if ( NULL != matvar->internal->fieldnames ) {
if ( NULL != matvar->internal->fieldnames && NULL != fields ) {
for ( i = 0; i < nelems_x_nfields; i++ ) {
if ( NULL == fields[i] ) {
printf(" Name: %s\n Rank: %d\n",
Expand Down
6 changes: 4 additions & 2 deletions src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@

/** Get type from tag */
#define TYPE_FROM_TAG(a) \
(((a) & 0x000000ff) <= MAT_T_FUNCTION) ? (enum matio_types)((a) & 0x000000ff) : MAT_T_UNKNOWN
(((a)&0x000000ff) <= MAT_T_FUNCTION) ? (enum matio_types)((a)&0x000000ff) : MAT_T_UNKNOWN
/** Get class from array flag */
#define CLASS_FROM_ARRAY_FLAGS(a) \
(((a) & 0x000000ff) <= MAT_C_OPAQUE) ? ((enum matio_classes)((a) & 0x000000ff)) : MAT_C_EMPTY
(((a)&0x000000ff) <= MAT_C_OPAQUE) ? ((enum matio_classes)((a)&0x000000ff)) : MAT_C_EMPTY
/** Class type mask */
#define CLASS_TYPE_MASK 0x000000ff

Expand Down Expand Up @@ -1528,6 +1528,7 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar)

matvar->data = calloc(nelems_x_nfields, matvar->data_size);
if ( NULL == matvar->data ) {
matvar->nbytes = 0;
Mat_Critical("Couldn't allocate memory for the data");
return bytesread;
}
Expand Down Expand Up @@ -1801,6 +1802,7 @@ ReadNextStructField(mat_t *mat, matvar_t *matvar)

matvar->data = calloc(nelems_x_nfields, matvar->data_size);
if ( NULL == matvar->data ) {
matvar->nbytes = 0;
Mat_Critical("Couldn't allocate memory for the data");
return bytesread;
}
Expand Down

0 comments on commit 915d657

Please sign in to comment.