diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2010-04-27 20:20:01 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2010-04-27 20:20:01 (GMT) |
commit | e331b971622ef4386b0cf2cdf468168df8ff03a9 (patch) | |
tree | 6d5b5eb66325bc3d608c0ac19d391583a17ea37b | |
parent | 4966f07945ca826d5d1f2c2d19892fee508503a9 (diff) | |
download | hdf5-e331b971622ef4386b0cf2cdf468168df8ff03a9.zip hdf5-e331b971622ef4386b0cf2cdf468168df8ff03a9.tar.gz hdf5-e331b971622ef4386b0cf2cdf468168df8ff03a9.tar.bz2 |
[svn-r18641] Description:
Added a null character to terminate a fixed-length string returned
by H5Aread.
Platforms tested:
Linux/32 2.6 (jam)
FreeBSD/64 6.3 (liberty)
-rw-r--r-- | c++/src/H5Attribute.cpp | 7 | ||||
-rw-r--r-- | c++/test/trefer.cpp | 19 |
2 files changed, 16 insertions, 10 deletions
diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index cf53526..27061de 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -423,18 +423,15 @@ void Attribute::p_read_fixed_len(const DataType& mem_type, H5std_string& strg) c // If there is data, allocate buffer and read it. if (attr_size > 0) { - char *strg_C = NULL; - - strg_C = new char [(size_t)attr_size+1]; + char *strg_C = new char[(size_t)attr_size+1]; herr_t ret_value = H5Aread(id, mem_type.getId(), strg_C); - if( ret_value < 0 ) { delete []strg_C; // de-allocate for fixed-len string throw AttributeIException("Attribute::read", "H5Aread failed"); } - // Get string from the C char* and release resource allocated locally + strg_C[attr_size] = '\0'; strg = strg_C; delete []strg_C; } diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index 3875dfd..16f6628 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -216,11 +216,20 @@ static void test_reference_obj(void) H5std_string read_comment1 = group.getComment(".", 10); verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__); - // Test that getComment handles failures gracefully - try { - H5std_string read_comment_tmp = group.getComment(NULL); - } - catch (Exception E) {} // We expect this to fail + // Test that getComment handles failures gracefully + try { + H5std_string read_comment_tmp = group.getComment(NULL); + } + catch (Exception E) {} // We expect this to fail + + // Test reading the name of an item in the group + H5std_string name; + name = group.getObjnameByIdx(0); + verify_val(name, "Dataset1", "Group::getObjnameByIdx", __LINE__, __FILE__); + name.clear(); + ssize_t name_size = group.getObjnameByIdx(0, name, 5); + verify_val(name, "Data", "Group::getObjnameByIdx(index,buf,buf_len)", __LINE__, __FILE__); + verify_val(name_size, 8, "Group::getObjnameByIdx(index,buf,buf_len)", __LINE__, __FILE__); // Close group group.close(); |