summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
authorScot Breitenfeld <brtnfld@hdfgroup.org>2008-04-30 19:51:13 (GMT)
committerScot Breitenfeld <brtnfld@hdfgroup.org>2008-04-30 19:51:13 (GMT)
commitaec106e324ce20e5efb725c25a6a333c7970127b (patch)
tree234df369115a46b08037c5f385061cf58823e497 /c++/src
parent5773fd34bc5adf59b4530d95ac9f0c0585902803 (diff)
downloadhdf5-aec106e324ce20e5efb725c25a6a333c7970127b.zip
hdf5-aec106e324ce20e5efb725c25a6a333c7970127b.tar.gz
hdf5-aec106e324ce20e5efb725c25a6a333c7970127b.tar.bz2
[svn-r14903] Undoing change committed in r14902.
Diffstat (limited to 'c++/src')
-rw-r--r--c++/src/H5Attribute.cpp30
-rw-r--r--c++/src/H5PropList.cpp34
2 files changed, 40 insertions, 24 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp
index 1bca691..043dc4d 100644
--- a/c++/src/H5Attribute.cpp
+++ b/c++/src/H5Attribute.cpp
@@ -131,22 +131,36 @@ void Attribute::read( const DataType& mem_type, void *buf ) const
///\exception H5::AttributeIException
// Programmer Binh-Minh Ribler - Apr, 2003
// Modification
-// 2006/12/9 - H5Aread allocates memory for character string
-// buffer with malloc, therefore, no allocation here,
-// but HDfree is needed. - BMR
+// Mar 2008
+// Corrected a misunderstanding that H5Aread would allocate
+// space for the buffer. Obtained the attribute size and
+// allocated memory properly. - BMR
//--------------------------------------------------------------------------
void Attribute::read( const DataType& mem_type, H5std_string& strg ) const
{
- char* strg_C; // temporary C-string for C API
+ // Get the attribute size and allocate temporary C-string for C API
+ hsize_t attr_size = H5Aget_storage_size(id);
+ if (attr_size <= 0)
+ {
+ throw AttributeIException("Attribute::read", "Unable to get attribute size before reading");
+ }
+ char* strg_C = new char [attr_size+1];
+ if (strg_C == NULL)
+ {
+ throw AttributeIException("Attribute::read", "Unable to allocate buffer to read the attribute");
+ }
- // call C API to get the attribute string of chars
- herr_t ret_value = H5Aread( id, mem_type.getId(), &strg_C);
+ // Call C API to get the attribute data, a string of chars
+ herr_t ret_value = H5Aread(id, mem_type.getId(), &strg_C);
if( ret_value < 0 )
{
throw AttributeIException("Attribute::read", "H5Aread failed");
}
- strg = strg_C; // get 'string' from the C char*
- HDfree(strg_C);
+
+ // Get 'string' from the C char* and release resource
+ strg_C[attr_size] = '\0';
+ strg = strg_C;
+ delete []strg_C;
}
//--------------------------------------------------------------------------
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index 136fb3b..76bc089 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -25,6 +25,7 @@
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
+#include "H5private.h" // for HDfree
#ifndef H5_NO_NAMESPACE
namespace H5 {
@@ -157,7 +158,7 @@ void PropList::copyProp(PropList& dest, const char *name) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param dest - IN: Destination property list or class
-///\param name - IN: Name of the property to copy - \c std::string
+///\param name - IN: Name of the property to copy - \c H5std_string
// Programmer Binh-Minh Ribler - Jul, 2005
//--------------------------------------------------------------------------
void PropList::copyProp( PropList& dest, const H5std_string& name ) const
@@ -194,7 +195,7 @@ void PropList::copyProp( PropList& dest, PropList& src, const char *name ) const
/// accepts. - Obsolete
///\param dest - IN: Destination property list or class
///\param src - IN: Source property list or class
-///\param name - IN: Name of the property to copy - \c std::string
+///\param name - IN: Name of the property to copy - \c H5std_string
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name ) const
@@ -273,7 +274,7 @@ bool PropList::propExist(const char* name ) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to check for - \c std::string
+///\param name - IN: Name of property to check for - \c H5std_string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
bool PropList::propExist(const H5std_string& name ) const
@@ -326,7 +327,7 @@ void PropList::getProperty(const char* name, void* value) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param name - IN: Name of property to query - \c char pointer
-///\return The property that is a \c std::string.
+///\return The property that is a \c H5std_string.
///\exception H5::PropListIException
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -343,7 +344,7 @@ H5std_string PropList::getProperty(const char* name) const
}
// Return propety value as a string after deleting temp C-string
- H5std_string prop_strg = H5std_string(prop_strg_C);
+ H5std_string prop_strg(prop_strg_C);
delete []prop_strg_C;
return (prop_strg);
}
@@ -352,7 +353,7 @@ H5std_string PropList::getProperty(const char* name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c std::string
+///\param name - IN: Name of property to query - \c H5std_string
///\param value - OUT: Pointer to the buffer for the property value
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -365,8 +366,8 @@ void PropList::getProperty(const H5std_string& name, void* value) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c std::string
-///\return The property that is a \c std::string.
+///\param name - IN: Name of property to query - \c H5std_string
+///\return The property that is a \c H5std_string.
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
H5std_string PropList::getProperty(const H5std_string& name) const
@@ -402,7 +403,7 @@ size_t PropList::getPropSize(const char *name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to query - \c std::string
+///\param name - IN: Name of property to query - \c H5std_string
///
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -421,12 +422,13 @@ size_t PropList::getPropSize(const H5std_string& name) const
H5std_string PropList::getClassName() const
{
char* temp_str;
- temp_str = H5Pget_class_name(id);
+ temp_str = H5Pget_class_name(id); // this API specified that temp_str must
+ // be freed.
if (temp_str != NULL)
{
- H5std_string class_name = H5std_string(temp_str);
- free(temp_str);
+ H5std_string class_name(temp_str);
+ HDfree(temp_str);
return(class_name);
}
else
@@ -489,7 +491,7 @@ void PropList::setProperty(const char* name, const char* charptr) const
/// It differs from the above function only in what arguments it
/// accepts.
///\param name - IN: Name of property to set - \c char pointer
-///\param strg - IN: Value for the property is a \c std::string
+///\param strg - IN: Value for the property is a \c H5std_string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void PropList::setProperty(const char* name, H5std_string& strg) const
@@ -502,7 +504,7 @@ void PropList::setProperty(const char* name, H5std_string& strg) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to set - \c std::string
+///\param name - IN: Name of property to set - \c H5std_string
///\param value - IN: Void pointer to the value for the property
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -516,7 +518,7 @@ void PropList::setProperty(const H5std_string& name, void* value) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to set - \c std::string
+///\param name - IN: Name of property to set - \c H5std_string
///\param strg - IN: Value for the property is a \c std::string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
@@ -569,7 +571,7 @@ void PropList::removeProp(const char *name) const
///\brief This is an overloaded member function, provided for convenience.
/// It differs from the above function only in what arguments it
/// accepts.
-///\param name - IN: Name of property to remove - \c std::string
+///\param name - IN: Name of property to remove - \c H5std_string
// Programmer: Binh-Minh Ribler - April, 2004
//--------------------------------------------------------------------------
void PropList::removeProp(const H5std_string& name) const