summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/html/RM_H5G.html28
-rw-r--r--release_docs/RELEASE.txt3
-rw-r--r--src/H5G.c11
-rw-r--r--test/titerate.c51
4 files changed, 52 insertions, 41 deletions
diff --git a/doc/html/RM_H5G.html b/doc/html/RM_H5G.html
index ee7b596..34ae2bf 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.
@@ -902,8 +903,7 @@ create or access function.
</dl>
<dt><strong>Returns:</strong>
<dd>Returns the size of the object name if successful,
- or <code>0</code> if no name is associated with the group identifier.
- Otherwise returns a negative value.
+ otherwise returns a negative value.
</dl>
@@ -911,16 +911,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 +978,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 2d9b586..524184c 100644
--- a/release_docs/RELEASE.txt
+++ b/release_docs/RELEASE.txt
@@ -74,6 +74,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
diff --git a/src/H5G.c b/src/H5G.c
index 896b9bc..cf38421 100644
--- a/src/H5G.c
+++ b/src/H5G.c
@@ -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");
@@ -2634,12 +2632,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 ee926ea..1624196 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 */
@@ -199,17 +199,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(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");
obj_type = H5Gget_objtype_by_idx(root_group, (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(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");
@@ -227,17 +227,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 */
@@ -730,7 +730,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 */
@@ -791,7 +792,6 @@ static void test_grp_memb_funcs(void)
/* Sort the dataset names */
qsort(dnames,NDATASETS+2,sizeof(char *),iter_strcmp);
-
/* Iterate through the datasets in the root group in various ways */
file=H5Fopen(DATAFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
CHECK(file, FAIL, "H5Fopen");
@@ -809,28 +809,35 @@ static void test_grp_memb_funcs(void)
for(i=0; i< (int)num_membs; i++) {
H5G_obj_t obj_type; /* Type of object in file */
- ret = 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");
obj_type = H5Gget_objtype_by_idx(root_group, (hsize_t)i);
- CHECK(obj_type, H5G_UNKNOWN, "H5Gget_objsname_by_idx");
+ CHECK(obj_type, H5G_UNKNOWN, "H5Gget_objtype_by_idx");
if(!HDstrcmp(dataset_name, "grp"))
- VERIFY(obj_type, H5G_GROUP, "H5Gget_objsname_by_idx");
+ VERIFY(obj_type, H5G_GROUP, "H5Gget_objname_by_idx");
if(!HDstrcmp(dataset_name, "dtype"))
- VERIFY(obj_type, H5G_TYPE, "H5Gget_objsname_by_idx");
+ VERIFY(obj_type, H5G_TYPE, "H5Gget_objname_by_idx");
if(!HDstrncmp(dataset_name, "Dataset", 7))
- VERIFY(obj_type, H5G_DATASET, "H5Gget_objsname_by_idx");
+ VERIFY(obj_type, 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);