diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2003-08-26 18:37:33 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2003-08-26 18:37:33 (GMT) |
commit | 15e1a2c0c0d53d264a5b4ea4f28d7beba6ccf1bd (patch) | |
tree | bd9d8d1d93916068eef38c224587a657e6828662 | |
parent | ff8132d5103a0a0399bd6cbc1faf6168c92db806 (diff) | |
download | hdf5-15e1a2c0c0d53d264a5b4ea4f28d7beba6ccf1bd.zip hdf5-15e1a2c0c0d53d264a5b4ea4f28d7beba6ccf1bd.tar.gz hdf5-15e1a2c0c0d53d264a5b4ea4f28d7beba6ccf1bd.tar.bz2 |
[svn-r7413] Purpose:
Bug fix
Description:
H5Gget_objname_by_idx should allow NULL for the 'name' parameter, to allow
for querying for the name's length.
Solution:
Allow NULL for the 'name' parameter, the internal functions were already
ready to handle that case.
Clean up RM information about H5Gget_objname_by_idx and
H5Gget_objtype_by_idx also.
Platforms tested:
FreeBSD 4.8 (sleipnir)
h5committest
-rw-r--r-- | doc/html/RM_H5G.html | 25 | ||||
-rw-r--r-- | release_docs/RELEASE.txt | 3 | ||||
-rw-r--r-- | src/H5G.c | 11 | ||||
-rw-r--r-- | test/titerate.c | 50 |
4 files changed, 51 insertions, 38 deletions
diff --git a/doc/html/RM_H5G.html b/doc/html/RM_H5G.html index 84acb60..d39939f 100644 --- a/doc/html/RM_H5G.html +++ b/doc/html/RM_H5G.html @@ -857,7 +857,7 @@ create or access function. <dl> <dt><strong>Name:</strong> <a name="Group-GetObjNameByIdx">H5Gget_objname_by_idx</a> <dt><strong>Signature:</strong> - <dd><em>ssize_t</em> <code>H5Gget_objname_by_idx</code>(<em>hid_t</em> <code>group_id</code>, + <dd><em>ssize_t</em> <code>H5Gget_objname_by_idx</code>(<em>hid_t</em> <code>loc_id</code>, <em>hsize_t</em> <code>idx</code>, <em>char *</em><code>name</code>, <em>size_t*</em> <code>size</code> ) @@ -865,10 +865,10 @@ create or access function. <dd>Returns a name of an object specified by an index. <dt><strong>Description:</strong> <dd><code>H5Gget_objname_by_idx</code> returns a name of the object - specified by the index <code>idx</code> in the group <code>group_id</code>. + specified by the index <code>idx</code> in the group <code>loc_id</code>. <p> - The group is specified by a group identifier <code>group_id</code>. - If preferred, a file identifier may be passed in <code>group_id</code>; + The group is specified by a group identifier <code>loc_id</code>. + If preferred, a file identifier may be passed in <code>loc_id</code>; that file's root group will be assumed. <p> <code>idx</code> is the transient index used to iterate through @@ -886,12 +886,13 @@ create or access function. the object name is truncated to <code>max_size - 1</code> characters. <p> Note that if the size of the object's name is unkown, a - preliminary call to <code>H5Gget_objname_by_idx</code> will return - that value. A second call to <code>H5Gget_objname_by_idx</code> + preliminary call to <code>H5Gget_objname_by_idx</code> with <code>name</code> + set to NULL will return the length of the object's name. + A second call to <code>H5Gget_objname_by_idx</code> can then be used to retrieve the actual name. <dt><strong>Parameters:</strong> <dl> - <dt><em>hid_t</em> <code>group_id</code> + <dt><em>hid_t</em> <code>loc_id</code> <dd>IN: Group or file identifier. <dt><em>hsize_t</em> <code>idx</code> <dd>IN: Transient index identifying object. @@ -911,16 +912,16 @@ create or access function. <dl> <dt><strong>Name:</strong> <a name="Group-GetObjTypeByIdx">H5Gget_objtype_by_idx</a> <dt><strong>Signature:</strong> - <dd><em>int</em> <code>H5Gget_objtype_by_idx</code>(<em>hid_t</em> <code>group_id</code>, + <dd><em>int</em> <code>H5Gget_objtype_by_idx</code>(<em>hid_t</em> <code>loc_id</code>, <em>hsize_t</em> <code>idx</code> ) <dt><strong>Purpose:</strong> <dd>Returns the type of an object specified by an index. <dt><strong>Description:</strong> <dd><code>H5Gget_objtype_by_idx</code> returns the type of the object - specified by the index <code>idx</code> in the group <code>group_id</code>. + specified by the index <code>idx</code> in the group <code>loc_id</code>. <p> - The group is specified by a group identifier <code>group_id</code>. - If preferred, a file identifier may be passed in <code>group_id</code>; + The group is specified by a group identifier <code>loc_id</code>. + If preferred, a file identifier may be passed in <code>loc_id</code>; that file's root group will be assumed. <p> <code>idx</code> is the transient index used to iterate through @@ -978,7 +979,7 @@ create or access function. <dt><strong>Parameters:</strong> <dl> - <dt><em>hid_t</em> <code>group_id</code> + <dt><em>hid_t</em> <code>loc_id</code> <dd>IN: Group or file identifier. <dt><em>hsize_t</em> <code>idx</code> <dd>IN: Transient index identifying object. diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index b2f7a5f..8f55693 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -56,6 +56,9 @@ Bug Fixes since HDF5-1.6.0 release Library ------- + - Corrected bug in H5Gget_objname_by_idx which was not allowing NULL + for the name when just querying for the object name's length. + QAK - 2003/08/25 - Corrected bug in variable-length string handling which could generate a core dump on writing variable-length strings as part of a compound datatype on certain architectures. QAK - 2003/08/25 @@ -520,8 +520,6 @@ H5Gget_objname_by_idx(hid_t loc_id, hsize_t idx, char *name, size_t size) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a location ID"); if(H5G_get_type(loc,H5AC_ind_dxpl_id)!=H5G_GROUP) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a group"); - if (!name) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "nil pointer for name"); if (H5G_get_num_objs(loc, &num_objs, H5AC_ind_dxpl_id)<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "unable to retrieve number of members"); @@ -2669,12 +2667,15 @@ H5G_get_objname_by_idx(H5G_entry_t *loc, hsize_t idx, char* name, size_t size, h H5G_node_name, loc->cache.stab.btree_addr, &udata))<0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "iteration operator failed"); + /* Get the length of the name */ ret_value = (ssize_t)HDstrlen(udata.name); - if(name && size>0) { - HDstrncpy(name, udata.name, MIN((size_t)(ret_value+1),size-1)); + + /* Copy the name into the user's buffer, if given */ + if(name) { + HDstrncpy(name, udata.name, MIN((size_t)(ret_value+1),size)); if((size_t)ret_value >= size) name[size-1]='\0'; - } + } /* end if */ done: /* Free the duplicated name */ diff --git a/test/titerate.c b/test/titerate.c index 0c9ca5d..645bea3 100644 --- a/test/titerate.c +++ b/test/titerate.c @@ -118,7 +118,7 @@ static void test_iter_group(void) int idx; /* Index in the group */ char name[NAMELEN]; /* temporary name buffer */ char *dnames[NDATASETS];/* Names of the datasets created */ - char dataset_name[16]; /* dataset name */ + char dataset_name[NAMELEN]; /* dataset name */ iter_info info; /* Custom iteration information */ hsize_t num_membs; /* Number of group members */ herr_t ret; /* Generic return value */ @@ -197,17 +197,17 @@ static void test_iter_group(void) VERIFY(num_membs,NDATASETS+2,"H5Gget_num_objs"); for(i=0; i< (int)num_membs; i++) { - ret = H5Gget_objname_by_idx(root_group, (hsize_t)i, dataset_name, 32); - CHECK(ret, FAIL, "H5Gget_objsname_by_idx"); + ret = H5Gget_objname_by_idx(root_group, (hsize_t)i, dataset_name, NAMELEN); + CHECK(ret, FAIL, "H5Gget_objname_by_idx"); ret = (herr_t)H5Gget_objtype_by_idx(root_group, (hsize_t)i); - CHECK(ret, FAIL, "H5Gget_objsname_by_idx"); + CHECK(ret, FAIL, "H5Gget_objtype_by_idx"); } H5E_BEGIN_TRY { - ret = (herr_t)H5Gget_objname_by_idx(root_group, (hsize_t)(NDATASETS+3), dataset_name, 16); + ret = (herr_t)H5Gget_objname_by_idx(root_group, (hsize_t)(NDATASETS+3), dataset_name, NAMELEN); } H5E_END_TRY; - VERIFY(ret, FAIL, "H5Gget_objsname_by_idx"); + VERIFY(ret, FAIL, "H5Gget_objname_by_idx"); ret = H5Gclose(root_group); CHECK(ret, FAIL, "H5Gclose"); @@ -225,17 +225,17 @@ static void test_iter_group(void) for(i=0; i< (int)num_membs; i++) { H5G_obj_t obj_type; /* Type of object in file */ - ret = H5Gget_objname_by_idx(file, (hsize_t)i, dataset_name, 32); - CHECK(ret, FAIL, "H5Gget_objsname_by_idx"); + ret = H5Gget_objname_by_idx(file, (hsize_t)i, dataset_name, NAMELEN); + CHECK(ret, FAIL, "H5Gget_objname_by_idx"); obj_type = H5Gget_objtype_by_idx(file, (hsize_t)i); - CHECK(obj_type, H5G_UNKNOWN, "H5Gget_objsname_by_idx"); + CHECK(obj_type, H5G_UNKNOWN, "H5Gget_objtype_by_idx"); } H5E_BEGIN_TRY { - ret = (herr_t)H5Gget_objname_by_idx(file, (hsize_t)(NDATASETS+3), dataset_name, 16); + ret = (herr_t)H5Gget_objname_by_idx(file, (hsize_t)(NDATASETS+3), dataset_name, NAMELEN); } H5E_END_TRY; - VERIFY(ret, FAIL, "H5Gget_objsname_by_idx"); + VERIFY(ret, FAIL, "H5Gget_objname_by_idx"); } /* Test invalid indices for starting iteration */ @@ -728,7 +728,8 @@ static void test_grp_memb_funcs(void) char name[NAMELEN]; /* temporary name buffer */ char *dnames[NDATASETS+2];/* Names of the datasets created */ char *obj_names[NDATASETS+2];/* Names of the objects in group */ - char dataset_name[16]; /* dataset name */ + char dataset_name[NAMELEN]; /* dataset name */ + ssize_t name_len; /* Length of object's name */ hsize_t num_membs; /* Number of group members */ herr_t ret; /* Generic return value */ @@ -805,28 +806,35 @@ static void test_grp_memb_funcs(void) VERIFY(num_membs,NDATASETS+2,"H5Gget_num_objs"); for(i=0; i< (int)num_membs; i++) { - ret = (herr_t)H5Gget_objname_by_idx(root_group, (hsize_t)i, dataset_name, 32); - CHECK(ret, FAIL, "H5Gget_objsname_by_idx"); + /* Test with NULL for name, to query length */ + name_len = H5Gget_objname_by_idx(root_group, (hsize_t)i, NULL, NAMELEN); + CHECK(name_len, FAIL, "H5Gget_objname_by_idx"); + + ret = H5Gget_objname_by_idx(root_group, (hsize_t)i, dataset_name, NAMELEN); + CHECK(ret, FAIL, "H5Gget_objname_by_idx"); + + /* Double-check that the length is the same */ + VERIFY(ret, name_len, "H5Gget_objname_by_idx"); /* Keep a copy of the dataset names around for later */ obj_names[i]=HDstrdup(dataset_name); - CHECK(dnames[i], NULL, "strdup"); + CHECK(obj_names[i], NULL, "strdup"); ret = (herr_t)H5Gget_objtype_by_idx(root_group, (hsize_t)i); - CHECK(ret, FAIL, "H5Gget_objsname_by_idx"); + CHECK(ret, FAIL, "H5Gget_objtype_by_idx"); if(!HDstrcmp(dataset_name, "grp")) - VERIFY(ret, H5G_GROUP, "H5Gget_objsname_by_idx"); + VERIFY(ret, H5G_GROUP, "H5Gget_objname_by_idx"); if(!HDstrcmp(dataset_name, "dtype")) - VERIFY(ret, H5G_TYPE, "H5Gget_objsname_by_idx"); + VERIFY(ret, H5G_TYPE, "H5Gget_objname_by_idx"); if(!HDstrncmp(dataset_name, "Dataset", 7)) - VERIFY(ret, H5G_DATASET, "H5Gget_objsname_by_idx"); + VERIFY(ret, H5G_DATASET, "H5Gget_objname_by_idx"); } H5E_BEGIN_TRY { - ret = (herr_t)H5Gget_objname_by_idx(root_group, (hsize_t)(NDATASETS+3), dataset_name, 16); + ret = (herr_t)H5Gget_objname_by_idx(root_group, (hsize_t)(NDATASETS+3), dataset_name, NAMELEN); } H5E_END_TRY; - VERIFY(ret, FAIL, "H5Gget_objsname_by_idx"); + VERIFY(ret, FAIL, "H5Gget_objname_by_idx"); /* Sort the dataset names */ qsort(obj_names,NDATASETS+2,sizeof(char *),iter_strcmp); |