summaryrefslogtreecommitdiffstats
path: root/c++/src/H5ArrayType.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2014-09-30 18:20:36 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2014-09-30 18:20:36 (GMT)
commit10f1e6acf8916a429f2cc925f49518cfc0015b6c (patch)
treef6078e3ae7987d9eb9737cfc1e8f3dc0e7f005b9 /c++/src/H5ArrayType.cpp
parent0befe65753b60e85891453dcbca373763a070419 (diff)
downloadhdf5-10f1e6acf8916a429f2cc925f49518cfc0015b6c.zip
hdf5-10f1e6acf8916a429f2cc925f49518cfc0015b6c.tar.gz
hdf5-10f1e6acf8916a429f2cc925f49518cfc0015b6c.tar.bz2
[svn-r25640] Purpose: Fixed HDFFV-4259
Description: - Used H5I_INVALID_HID instead of 0 to initialized member "id" in classes that represent HDF5 objects. For PropList, H5P_DEFAULT has to be used instead of H5I_INVALID_HID. - Added try/catch block to some dynamically allocating memory code and re-throw the bad_alloc exception with a message informing the location of the failure. Platforms tested: Linux/ppc64 (ostrich) Linux/32 2.6 (jam) SunOS 5.11 (emu)
Diffstat (limited to 'c++/src/H5ArrayType.cpp')
-rw-r--r--c++/src/H5ArrayType.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp
index 852658b..5a3f860 100644
--- a/c++/src/H5ArrayType.cpp
+++ b/c++/src/H5ArrayType.cpp
@@ -54,15 +54,18 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
rank = H5Tget_array_ndims(existing_id);
if (rank < 0)
{
- throw DataTypeIException("ArrayType overloaded constructor", "H5Tget_array_ndims failed");
+ throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims failed");
}
- // Get the dimensions of the existing array and store it in this array
- dimensions = new hsize_t[rank];
- //hsize_t rdims2[H5S_MAX_RANK];
- int ret_value = H5Tget_array_dims2(id, dimensions);
- if (ret_value < 0)
- throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed");
+ // Get the dimensions of the existing array and store it in this array
+ try {
+ dimensions = new hsize_t[rank];
+ } catch (const std::bad_alloc&) {
+ throw DataTypeIException("ArrayType constructor (existing id)", "Memory allocation failed");
+ }
+ int ret_value = H5Tget_array_dims2(id, dimensions);
+ if (ret_value < 0)
+ throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_dims2 failed");
}
//--------------------------------------------------------------------------
@@ -72,10 +75,14 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
//--------------------------------------------------------------------------
ArrayType::ArrayType( const ArrayType& original ) : DataType( original )
{
- rank = original.rank;
- dimensions = new hsize_t[rank];
- for (int i = 0; i < rank; i++)
- dimensions[i] = original.dimensions[i];
+ rank = original.rank;
+ try {
+ dimensions = new hsize_t[rank];
+ } catch (const std::bad_alloc&) {
+ throw DataTypeIException("ArrayType constructor (existing id)", "Memory allocation failed");
+ }
+ for (int i = 0; i < rank; i++)
+ dimensions[i] = original.dimensions[i];
}
//--------------------------------------------------------------------------
@@ -90,14 +97,18 @@ ArrayType::ArrayType( const ArrayType& original ) : DataType( original )
//--------------------------------------------------------------------------
ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims) : DataType()
{
- hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims);
- if (new_type_id < 0)
- throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed");
- id = new_type_id;
- rank = ndims;
- dimensions = new hsize_t[rank];
- for (int i = 0; i < rank; i++)
- dimensions[i] = dims[i];
+ hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims);
+ if (new_type_id < 0)
+ throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed");
+ id = new_type_id;
+ rank = ndims;
+ try {
+ dimensions = new hsize_t[rank];
+ } catch (const std::bad_alloc&) {
+ throw DataTypeIException("ArrayType constructor (existing id)", "Memory allocation failed");
+ }
+ for (int i = 0; i < rank; i++)
+ dimensions[i] = dims[i];
}
//--------------------------------------------------------------------------
@@ -140,7 +151,11 @@ int ArrayType::getArrayDims(hsize_t* dims)
throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed");
// store the array's info in memory
rank = ndims;
- dimensions = new hsize_t[rank];
+ try {
+ dimensions = new hsize_t[rank];
+ } catch (const std::bad_alloc&) {
+ throw DataTypeIException("ArrayType constructor (existing id)", "Memory allocation failed");
+ }
for (int i = 0; i < rank; i++)
dimensions[i] = dims[i];
}