[svn-r22129] HDFFV-7777: Fix for removing NULL character from fortran string in h5lt_get_attribute_string_f

Fixed size +1 error in HD5f2cstring
This commit is contained in:
Scot Breitenfeld 2012-03-22 23:18:59 -05:00
parent 19a6303205
commit 213ab6eb36
4 changed files with 33 additions and 20 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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;
/*
* Allocate buffer to hold C attribute string
*/
if ((c_buf = HDmalloc((size_t)*buf_size + 1)) == 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);
* 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;

View File

@ -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