summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScot Breitenfeld <brtnfld@hdfgroup.org>2012-03-23 04:18:59 (GMT)
committerScot Breitenfeld <brtnfld@hdfgroup.org>2012-03-23 04:18:59 (GMT)
commit213ab6eb36e398b5d0db55df002875ffcdeb4122 (patch)
tree526e07f3f28faafd10a517a043347f3fa26e4be7
parent19a6303205d070f62f2579168397579001a38fe5 (diff)
downloadhdf5-213ab6eb36e398b5d0db55df002875ffcdeb4122.zip
hdf5-213ab6eb36e398b5d0db55df002875ffcdeb4122.tar.gz
hdf5-213ab6eb36e398b5d0db55df002875ffcdeb4122.tar.bz2
[svn-r22129] HDFFV-7777: Fix for removing NULL character from fortran string in h5lt_get_attribute_string_f
Fixed size +1 error in HD5f2cstring
-rwxr-xr-xhl/fortran/src/H5DSfc.c4
-rwxr-xr-xhl/fortran/src/H5LTf90proto.h3
-rwxr-xr-xhl/fortran/src/H5LTfc.c32
-rwxr-xr-xhl/fortran/src/H5LTff.f9014
4 files changed, 33 insertions, 20 deletions
diff --git a/hl/fortran/src/H5DSfc.c b/hl/fortran/src/H5DSfc.c
index 6816347..3135cfa 100755
--- a/hl/fortran/src/H5DSfc.c
+++ b/hl/fortran/src/H5DSfc.c
@@ -283,7 +283,7 @@ nh5dsget_label_c(hid_t_f *did, int_f *idx, _fcd label, size_t_f *size)
* Convert C name to FORTRAN and place it in the given buffer
*/
- HD5packFstring(c_label, _fcdtocp(label), (size_t)*size+1);
+ HD5packFstring(c_label, _fcdtocp(label), (size_t)*size);
done:
*size = (size_t_f)size_c; /* Don't subtract '1' because H5DSget_label doesn't include the
@@ -332,7 +332,7 @@ nh5dsget_scale_name_c(hid_t_f *did, _fcd name, size_t_f *size)
* Convert C name to FORTRAN and place it in the given buffer
*/
if(size_c != 0) {
- HD5packFstring(c_scale_name, _fcdtocp(name), (size_t)*size+1);
+ HD5packFstring(c_scale_name, _fcdtocp(name), (size_t)*size);
*size = (size_t_f)size_c-1; /* (-1) because we don't include the NULL ending in the length*/
} else {
*size = (size_t_f)size_c; /* if NULL then no name was found */
diff --git a/hl/fortran/src/H5LTf90proto.h b/hl/fortran/src/H5LTf90proto.h
index 205871c..8618fc6 100755
--- a/hl/fortran/src/H5LTf90proto.h
+++ b/hl/fortran/src/H5LTf90proto.h
@@ -1140,7 +1140,8 @@ nh5ltget_attribute_string_c(hid_t_f *loc_id,
_fcd dsetname,
int_f *attrnamelen,
_fcd attrname,
- void *buf);
+ _fcd buf,
+ size_t_f *buf_size);
HDF5_HL_F90CSTUBDLL
int_f
diff --git a/hl/fortran/src/H5LTfc.c b/hl/fortran/src/H5LTfc.c
index c0b7695..674636d 100755
--- a/hl/fortran/src/H5LTfc.c
+++ b/hl/fortran/src/H5LTfc.c
@@ -17,8 +17,7 @@
#include "H5LTprivate.h"
#include "H5LTf90proto.h"
-
-
+#include "H5Eprivate.h"
/*-------------------------------------------------------------------------
* Function: H5LTmake_dataset_c
@@ -1719,13 +1718,13 @@ nh5ltget_attribute_string_c(hid_t_f *loc_id,
_fcd dsetname,
int_f *attrnamelen,
_fcd attrname,
- void *buf)
+ _fcd buf, size_t_f *buf_size)
{
int ret_value = -1;
herr_t ret;
- hid_t c_loc_id;
char *c_name = NULL;
char *c_attrname = NULL;
+ char *c_buf = NULL;
int c_namelen;
int c_attrnamelen;
@@ -1741,26 +1740,33 @@ nh5ltget_attribute_string_c(hid_t_f *loc_id,
c_attrname = (char *)HD5f2cstring(attrname, c_attrnamelen);
if (c_attrname == NULL)
goto done;
-
/*
- * Call H5LTget_attribute_int function.
- */
- c_loc_id = (hid_t)*loc_id;
-
- ret = H5LTget_attribute_string(c_loc_id,c_name,c_attrname,buf);
+ * Allocate buffer to hold C attribute string
+ */
+ if ((c_buf = HDmalloc((size_t)*buf_size + 1)) == NULL)
+ goto done;
+ /*
+ * Call H5LTget_attribute_int function.
+ */
+ ret = H5LTget_attribute_string((hid_t)*loc_id,c_name,c_attrname,c_buf);
if (ret < 0)
goto done;
- ret_value = 0;
+ /*
+ * Convert C name to FORTRAN and place it in the given buffer
+ */
+ HD5packFstring(c_buf, _fcdtocp(buf), (size_t)*buf_size);
+ ret_value = 0;
done:
if(c_name!=NULL)
free(c_name);
if(c_attrname!=NULL)
free(c_attrname);
-
+ if(c_buf!=NULL)
+ free(c_buf);
return ret_value;
}
@@ -2157,7 +2163,7 @@ nh5ltpath_valid_c(hid_t_f *loc_id,
/*
* convert FORTRAN name to C name
*/
- if( NULL == (c_path = (char *)HD5f2cstring(path, (int)*pathlen)))
+ if( NULL == (c_path = (char *)HD5f2cstring(path, (size_t)*pathlen)))
goto done;
check_object_valid = FALSE;
diff --git a/hl/fortran/src/H5LTff.f90 b/hl/fortran/src/H5LTff.f90
index 7d53ab7..b384821 100755
--- a/hl/fortran/src/H5LTff.f90
+++ b/hl/fortran/src/H5LTff.f90
@@ -5969,9 +5969,10 @@ CONTAINS
CHARACTER(len=*), INTENT(inout) :: buf ! data buffer
INTEGER :: namelen ! name length
INTEGER :: attrlen ! name length
+ INTEGER(size_t) :: buf_size ! buf size
INTERFACE
- INTEGER FUNCTION h5ltget_attribute_string_c(loc_id,namelen,dset_name,attrlen,attr_name,buf)
+ INTEGER FUNCTION h5ltget_attribute_string_c(loc_id,namelen,dset_name,attrlen,attr_name,buf,buf_size)
USE h5global
!DEC$IF DEFINED(HDF5F90_WINDOWS)
!DEC$ATTRIBUTES C,reference,decorate,alias:'H5LTGET_ATTRIBUTE_STRING_C'::h5ltget_attribute_string_c
@@ -5984,12 +5985,15 @@ CONTAINS
CHARACTER(len=*), INTENT(in) :: dset_name ! name of the dataset
CHARACTER(len=*), INTENT(in) :: attr_name ! name of the attribute
CHARACTER(len=*), INTENT(inout) :: buf ! data buffer
+ INTEGER(size_t) :: buf_size ! data buffer size
END FUNCTION h5ltget_attribute_string_c
END INTERFACE
namelen = LEN(dset_name)
attrlen = LEN(attr_name)
- errcode = h5ltget_attribute_string_c(loc_id,namelen,dset_name,attrlen,attr_name,buf)
+ buf_size = LEN(buf)
+
+ errcode = h5ltget_attribute_string_c(loc_id,namelen,dset_name,attrlen,attr_name,buf,buf_size)
END SUBROUTINE h5ltget_attribute_string_f
@@ -6360,14 +6364,16 @@ CONTAINS
END FUNCTION h5ltpath_valid_c
END INTERFACE
+ ! Initialize
+ path_valid = .FALSE.
+ errcode = 0
+
check_object_valid_c = 0
IF(check_object_valid) check_object_valid_c = 1
pathlen = LEN(path)
status = h5ltpath_valid_c(loc_id, path, pathlen, check_object_valid_c)
- path_valid = .FALSE.
- errcode = 0
IF(status.EQ.1)THEN
path_valid = .TRUE.
ELSE IF(status.LT.0)THEN