mirror of
https://github.com/nasa/trick.git
synced 2025-01-31 08:25:41 +00:00
handle invalid swap magic and delete dangling pointers MatLab.cpp
This commit is contained in:
parent
ac6fd26a6d
commit
d701040d22
@ -61,7 +61,7 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) {
|
|||||||
int array_type, array_bytes, array_flags[2];
|
int array_type, array_bytes, array_flags[2];
|
||||||
int array_complex, array_class ;
|
int array_complex, array_class ;
|
||||||
int dim_type, dim_bytes, num_dims;
|
int dim_type, dim_bytes, num_dims;
|
||||||
int * dims;
|
int * dims = nullptr;
|
||||||
int name_bytes;
|
int name_bytes;
|
||||||
char * name, * field_name, * variable_name;
|
char * name, * field_name, * variable_name;
|
||||||
int real_type, real_bytes;
|
int real_type, real_bytes;
|
||||||
@ -166,7 +166,10 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
num_dims = dim_bytes / 4;
|
num_dims = dim_bytes / 4;
|
||||||
|
// delete dangling pointer
|
||||||
|
if(dims) {
|
||||||
|
delete [] dims;
|
||||||
|
}
|
||||||
dims = new int[num_dims];
|
dims = new int[num_dims];
|
||||||
for (ii = 0; ii < num_dims; ii++) {
|
for (ii = 0; ii < num_dims; ii++) {
|
||||||
fread(&dims[ii], 4, 1, fp_) ;
|
fread(&dims[ii], 4, 1, fp_) ;
|
||||||
@ -300,7 +303,10 @@ MatLab::MatLab(char * file_name, char * param_name, char * time_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
num_dims = dim_bytes / 4;
|
num_dims = dim_bytes / 4;
|
||||||
|
// delete dangling pointer
|
||||||
|
if(dims) {
|
||||||
|
delete [] dims;
|
||||||
|
}
|
||||||
dims = new int[num_dims];
|
dims = new int[num_dims];
|
||||||
for (ii = 0; ii < num_dims; ii++) {
|
for (ii = 0; ii < num_dims; ii++) {
|
||||||
fread(&dims[ii], 4, 1, fp_) ;
|
fread(&dims[ii], 4, 1, fp_) ;
|
||||||
@ -697,6 +703,9 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) {
|
|||||||
swap = 0;
|
swap = 0;
|
||||||
} else if (magic == 0x494d) {
|
} else if (magic == 0x494d) {
|
||||||
swap = 1;
|
swap = 1;
|
||||||
|
} else {
|
||||||
|
std::cerr << "ERROR: MatLab.cpp swap magic is invalid, default to byte swap == false" << std::endl;
|
||||||
|
swap = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
param_found = time_found = false;
|
param_found = time_found = false;
|
||||||
@ -749,7 +758,10 @@ int MatLabLocateParam(char * file_name, char * param_name, char * time_name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
num_dims = dim_bytes / 4;
|
num_dims = dim_bytes / 4;
|
||||||
|
// delete dangling pointer
|
||||||
|
if(dims) {
|
||||||
|
delete [] dims;
|
||||||
|
}
|
||||||
dims = new int[num_dims];
|
dims = new int[num_dims];
|
||||||
for (ii = 0; ii < num_dims; ii++) {
|
for (ii = 0; ii < num_dims; ii++) {
|
||||||
fread(&dims[ii], 4, 1, fp) ;
|
fread(&dims[ii], 4, 1, fp) ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user