summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElena Pourmal <epourmal@hdfgroup.org>2001-07-16 19:57:03 (GMT)
committerElena Pourmal <epourmal@hdfgroup.org>2001-07-16 19:57:03 (GMT)
commitfe309eda4fa2012789b947b2471081725d18e27c (patch)
tree3d6a446ee80558b8258a638edae3720dfb24b005
parent00f62b983a2f2051adfd4dd619c8db9148472347 (diff)
downloadhdf5-fe309eda4fa2012789b947b2471081725d18e27c.zip
hdf5-fe309eda4fa2012789b947b2471081725d18e27c.tar.gz
hdf5-fe309eda4fa2012789b947b2471081725d18e27c.tar.bz2
[svn-r4216]
Purpose: Bug fix (bug#625) Description: Character buffers were not copied and freed properly. That caused segmentation fault on Linux (Debian 2.2, a glibc2.1.3-based distro and gcc 2.95.2 and NAGWare Fortran 95 compiler Release 4.0a(392). Also many compilers screamed about this piece of code. Solution: Asked Quincey to fix the code. Platforms tested: Linux (eirene)
-rw-r--r--fortran/src/H5Gf.c2
-rw-r--r--fortran/src/H5Git.c25
-rw-r--r--fortran/src/H5Git.h2
3 files changed, 19 insertions, 10 deletions
diff --git a/fortran/src/H5Gf.c b/fortran/src/H5Gf.c
index e86d342..a57b475 100644
--- a/fortran/src/H5Gf.c
+++ b/fortran/src/H5Gf.c
@@ -133,7 +133,7 @@ nh5gget_obj_info_idx_c
*/
c_loc_id = *loc_id;
c_idx = *idx;
- c_ret_value = H5Gget_obj_info_idx(c_loc_id, c_name, c_idx, &c_obj_name, &type);
+ c_ret_value = H5Gget_obj_info_idx(c_loc_id, c_name, c_idx, &c_obj_name, (size_t)*obj_namelen, &type);
if (c_ret_value < 0) {
HDfree(c_obj_name);
diff --git a/fortran/src/H5Git.c b/fortran/src/H5Git.c
index 4ffd8c8..2998753 100644
--- a/fortran/src/H5Git.c
+++ b/fortran/src/H5Git.c
@@ -10,8 +10,7 @@
#define FALSE 0
herr_t count_elems(hid_t loc_id, const char *name, void *opdata);
-/*herr_t obj_info(hid_t loc_id, const char *name, void *opdata);*/
-herr_t obj_info(hid_t loc_id, char *name, void *opdata);
+herr_t obj_info(hid_t loc_id, const char *name, void *opdata);
typedef struct retval {
char * name;
@@ -101,7 +100,7 @@ H5Gn_members( hid_t loc_id, char *group_name )
*-------------------------------------------------------------------------
*/
herr_t
-H5Gget_obj_info_idx( hid_t loc_id, char *group_name, int idx, char **objname, int *type )
+H5Gget_obj_info_idx( hid_t loc_id, char *group_name, int idx, char **objname, size_t max_objname_len, int *type )
{
int res;
retval_t retVal;
@@ -110,7 +109,19 @@ H5Gget_obj_info_idx( hid_t loc_id, char *group_name, int idx, char **objname, in
if (res < 0) {
return res;
}
- *objname = retVal.name;
+
+ /* Only play with the string if it was returned */
+ if(retVal.name!=NULL) {
+ /* Copy the name to return & truncate if necessary */
+ strncpy(*objname,retVal.name,max_objname_len);
+ (*objname)[max_objname_len]='\0';
+
+ /* Free the name we strdup'ed in obj_info() */
+ free(retVal.name);
+ } /* end if */
+ else
+ *(*objname)='\0';
+
*type = retVal.type;
return 0;
}
@@ -200,8 +211,7 @@ count_elems(hid_t loc_id, const char *name, void *opdata)
* group, or named datatype)
*/
static herr_t
-/*obj_info(hid_t loc_id, const char *name, void *opdata)*/
-obj_info(hid_t loc_id, char *name, void *opdata)
+obj_info(hid_t loc_id, const char *name, void *opdata)
{
herr_t res;
H5G_stat_t statbuf;
@@ -213,8 +223,7 @@ obj_info(hid_t loc_id, char *name, void *opdata)
return 1;
} else {
((retval_t *)opdata)->type = statbuf.type;
-/* ((retval_t *)opdata)->name = strdup(name); */
- ((retval_t *)opdata)->name = name;
+ ((retval_t *)opdata)->name = strdup(name);
return 1;
}
}
diff --git a/fortran/src/H5Git.h b/fortran/src/H5Git.h
index 7211440..20760b0 100644
--- a/fortran/src/H5Git.h
+++ b/fortran/src/H5Git.h
@@ -11,6 +11,6 @@
int H5Gn_members( hid_t loc_id, char *group_name );
-herr_t H5Gget_obj_info_idx( hid_t loc_id, char *group_name, int idx, char **objname, int *type );
+herr_t H5Gget_obj_info_idx( hid_t loc_id, char *group_name, int idx, char **objname, size_t max_objname_len, int *type );
#endif /*_H5Git_H*/