Skip to content
Snippets Groups Projects
Commit 19f47e44 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

add more error checks in StructuredField (cf. #1704)

parent b27816a8
No related branches found
No related tags found
No related merge requests found
...@@ -204,6 +204,11 @@ public: ...@@ -204,6 +204,11 @@ public:
input.read((char *)_d, 3 * sizeof(double)); input.read((char *)_d, 3 * sizeof(double));
input.read((char *)_n, 3 * sizeof(int)); input.read((char *)_n, 3 * sizeof(int));
int nt = _n[0] * _n[1] * _n[2]; int nt = _n[0] * _n[1] * _n[2];
if(nt <= 0) {
Msg::Error("Field %i: invalid number of data points %d x %d x %d",
this->id, _n[0], _n[1], _n[2]);
return MAX_LC;
}
if(_data) delete[] _data; if(_data) delete[] _data;
_data = new double[nt]; _data = new double[nt];
input.read((char *)_data, nt * sizeof(double)); input.read((char *)_data, nt * sizeof(double));
...@@ -212,6 +217,11 @@ public: ...@@ -212,6 +217,11 @@ public:
input >> _o[0] >> _o[1] >> _o[2] >> _d[0] >> _d[1] >> _d[2] >> input >> _o[0] >> _o[1] >> _o[2] >> _d[0] >> _d[1] >> _d[2] >>
_n[0] >> _n[1] >> _n[2]; _n[0] >> _n[1] >> _n[2];
int nt = _n[0] * _n[1] * _n[2]; int nt = _n[0] * _n[1] * _n[2];
if(nt <= 0) {
Msg::Error("Field %i: invalid number of data points %d x %d x %d",
this->id, _n[0], _n[1], _n[2]);
return MAX_LC;
}
if(_data) delete[] _data; if(_data) delete[] _data;
_data = new double[nt]; _data = new double[nt];
for(int i = 0; i < nt; i++) input >> _data[i]; for(int i = 0; i < nt; i++) input >> _data[i];
...@@ -222,6 +232,14 @@ public: ...@@ -222,6 +232,14 @@ public:
Msg::Error("Field %i: error reading file '%s'", this->id, Msg::Error("Field %i: error reading file '%s'", this->id,
_fileName.c_str()); _fileName.c_str());
} }
for(int i = 0; i < 3; i++) {
// if there is a single point, make sure _d[i] != 0
if(_n[i] == 1 && !_d[i]) _d[i] = 1.;
}
if(!_d[0] || !_d[1] || !_d[2]) {
Msg::Error("Field %i: Dx, Dy and Dz should be non zero", this->id);
return MAX_LC;
}
updateNeeded = false; updateNeeded = false;
} }
if(_errorStatus) return MAX_LC; if(_errorStatus) return MAX_LC;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment