Skip to content

Commit 9b91ce0

Browse files
committed
add check for valid dataspace_id before reading dims
1 parent 2627d09 commit 9b91ce0

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/io/APRWriter.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,19 @@ class Hdf5DataSet {
113113
}
114114

115115
std::vector<uint64_t> get_dimensions(){
116+
if(dataspace_id > -1) {
117+
const int ndims = H5Sget_simple_extent_ndims(dataspace_id);
118+
std::vector<hsize_t> _dims;
119+
_dims.resize(ndims, 0);
116120

117-
const int ndims = H5Sget_simple_extent_ndims(dataspace_id);
118-
std::vector<hsize_t> _dims;
119-
_dims.resize(ndims,0);
121+
H5Sget_simple_extent_dims(dataspace_id, _dims.data(), NULL);
120122

121-
H5Sget_simple_extent_dims(dataspace_id, _dims.data(), NULL);
122-
123-
std::vector<uint64_t> dims_u64;
124-
dims_u64.resize(ndims,0);
125-
std::copy(_dims.begin(),_dims.end(),dims_u64.begin());
126-
127-
return dims_u64;
123+
std::vector<uint64_t> dims_u64;
124+
dims_u64.resize(ndims, 0);
125+
std::copy(_dims.begin(), _dims.end(), dims_u64.begin());
126+
return dims_u64;
127+
}
128+
return {};
128129
}
129130

130131

0 commit comments

Comments
 (0)