summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScot Breitenfeld <brtnfld@hdfgroup.org>2014-09-30 22:16:33 (GMT)
committerScot Breitenfeld <brtnfld@hdfgroup.org>2014-09-30 22:16:33 (GMT)
commitf2535031952d9c848538043829d43108575cdce3 (patch)
treee453c00776fc144e3cd90bdab09ccece62b1efb5
parenta9ac64296a8c819d842ffd1dff225c888870c8dc (diff)
downloadhdf5-f2535031952d9c848538043829d43108575cdce3.zip
hdf5-f2535031952d9c848538043829d43108575cdce3.tar.gz
hdf5-f2535031952d9c848538043829d43108575cdce3.tar.bz2
[svn-r25642] merged changes 25614,25629,25631 into branch.
-rw-r--r--hl/fortran/test/tsttable.f9021
-rw-r--r--hl/src/H5DS.c65
-rw-r--r--hl/src/H5IM.c129
-rw-r--r--hl/src/H5LT.c107
-rw-r--r--hl/src/H5PT.c15
-rw-r--r--hl/src/H5TB.c111
-rw-r--r--hl/test/test_lite.c38
-rw-r--r--hl/test/test_table.c9
8 files changed, 459 insertions, 36 deletions
diff --git a/hl/fortran/test/tsttable.f90 b/hl/fortran/test/tsttable.f90
index 66ec5c6..bb88abf 100644
--- a/hl/fortran/test/tsttable.f90
+++ b/hl/fortran/test/tsttable.f90
@@ -175,13 +175,30 @@ SUBROUTINE test_table1()
CALL h5tbwrite_field_name_f(file_id,dsetname1,field_names(4),start,nrecords,type_sizer,&
bufr,errcode)
-
!-------------------------------------------------------------------------
! read field
!-------------------------------------------------------------------------
+ ! Read an invalid field, should fail
+ CALL h5tbread_field_name_f(file_id,dsetname1,'DoesNotExist',start,nrecords,type_sizec,&
+ bufsr,errcode)
+
+ IF(errcode.GE.0)THEN
+ PRINT *, 'error in h5tbread_field_name_f'
+ CALL h5fclose_f(file_id, errcode)
+ CALL h5close_f(errcode)
+ STOP
+ ENDIF
+
+ ! Read a valid field, should pass
CALL h5tbread_field_name_f(file_id,dsetname1,field_names(1),start,nrecords,type_sizec,&
bufsr,errcode)
+ IF(errcode.LT.0)THEN
+ PRINT *, 'error in h5tbread_field_name_f'
+ CALL h5fclose_f(file_id, errcode)
+ CALL h5close_f(errcode)
+ STOP
+ ENDIF
!
! compare read and write buffers.
@@ -329,8 +346,6 @@ SUBROUTINE test_table1()
! we insert a field callsed "field5" with the same type and buffer as field 4 (Real)
!-------------------------------------------------------------------------
-
-
CALL test_begin(' Insert field ')
CALL h5tbinsert_field_f(file_id,dsetname1,"field5",field_types(4),4,bufr,errcode)
diff --git a/hl/src/H5DS.c b/hl/src/H5DS.c
index a743e90..1f0f678 100644
--- a/hl/src/H5DS.c
+++ b/hl/src/H5DS.c
@@ -1444,6 +1444,9 @@ herr_t H5DSset_label(hid_t did, unsigned int idx, const char *label)
if (H5I_DATASET != it)
return FAIL;
+ if (label == NULL)
+ return FAIL;
+
/* get dataset space */
if ((sid = H5Dget_space(did)) < 0)
return FAIL;
@@ -1912,11 +1915,12 @@ out:
htri_t H5DSis_scale(hid_t did)
{
hid_t tid = -1; /* attribute type ID */
- hid_t aid; /* attribute ID */
+ hid_t aid = -1; /* attribute ID */
herr_t has_class; /* has the "CLASS" attribute */
htri_t is_ds; /* boolean return value */
H5I_type_t it; /* ID type */
- char buf[20];
+ char *buf; /* Name of attribute */
+ hsize_t storage_size; /* Size of storage for attribute */
/*-------------------------------------------------------------------------
* parameter checking
@@ -1944,19 +1948,41 @@ htri_t H5DSis_scale(hid_t did)
if((tid = H5Aget_type(aid)) < 0)
goto out;
+ /* check to make sure attribute is a string */
+ if(H5T_STRING != H5Tget_class(tid))
+ goto out;
+
+ /* check to make sure string is null-terminated */
+ if(H5T_STR_NULLTERM != H5Tget_strpad(tid))
+ goto out;
+
+ /* allocate buffer large enough to hold string */
+ if((storage_size = H5Aget_storage_size(aid)) == 0)
+ goto out;
+
+ buf = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1);
+ if(buf == NULL)
+ goto out;
+
+ /* Read the attribute */
if(H5Aread(aid, tid, buf) < 0)
- goto out;
+ goto out;
- if(strcmp(buf, DIMENSION_SCALE_CLASS)==0)
+ /* compare strings */
+ if(HDstrncmp(buf, DIMENSION_SCALE_CLASS, MIN(HDstrlen(DIMENSION_SCALE_CLASS),HDstrlen(buf)))==0)
is_ds = 1;
else
is_ds = 0;
+ HDfree(buf);
+
if(H5Tclose(tid) < 0)
goto out;
if (H5Aclose(aid) < 0)
goto out;
+
+
}
return is_ds;
@@ -2118,7 +2144,8 @@ herr_t H5DS_is_reserved(hid_t did)
int has_class;
hid_t tid = -1;
hid_t aid = -1;
- char buf[40];
+ char *buf; /* Name of attribute */
+ hsize_t storage_size; /* Size of storage for attribute */
herr_t ret;
/* try to find the attribute "CLASS" on the dataset */
@@ -2135,16 +2162,36 @@ herr_t H5DS_is_reserved(hid_t did)
if((tid = H5Aget_type(aid)) < 0)
goto out;
+ /* check to make sure attribute is a string */
+ if(H5T_STRING != H5Tget_class(tid))
+ goto out;
+
+ /* check to make sure string is null-terminated */
+ if(H5T_STR_NULLTERM != H5Tget_strpad(tid))
+ goto out;
+
+ /* allocate buffer large enough to hold string */
+ if((storage_size = H5Aget_storage_size(aid)) == 0)
+ goto out;
+
+ buf = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1);
+ if(buf == NULL)
+ goto out;
+
+ /* Read the attribute */
if(H5Aread(aid, tid, buf) < 0)
- goto out;
+ goto out;
+
- if(strcmp(buf, IMAGE_CLASS) == 0 ||
- strcmp(buf, PALETTE_CLASS) == 0 ||
- strcmp(buf, TABLE_CLASS) == 0 )
+ if(HDstrncmp(buf, IMAGE_CLASS, MIN(HDstrlen(IMAGE_CLASS),HDstrlen(buf))) == 0 ||
+ HDstrncmp(buf, PALETTE_CLASS, MIN(HDstrlen(PALETTE_CLASS),HDstrlen(buf))) == 0 ||
+ HDstrncmp(buf, TABLE_CLASS, MIN(HDstrlen(TABLE_CLASS),HDstrlen(buf))) == 0 )
ret = 1;
else
ret = 0;
+ HDfree(buf);
+
if (H5Tclose(tid) < 0)
goto out;
diff --git a/hl/src/H5IM.c b/hl/src/H5IM.c
index 0781e48..33b2dd4 100644
--- a/hl/src/H5IM.c
+++ b/hl/src/H5IM.c
@@ -46,6 +46,10 @@ herr_t H5IMmake_image_8bit( hid_t loc_id,
{
hsize_t dims[IMAGE8_RANK];
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Initialize the image dimensions */
dims[0] = height;
dims[1] = width;
@@ -103,9 +107,16 @@ herr_t H5IMmake_image_24bit( hid_t loc_id,
{
hsize_t dims[IMAGE24_RANK];
+ /* check the arguments */
+ if (interlace == NULL)
+ return -1;
+ if (dset_name == NULL)
+ return -1;
+
+
/* Initialize the image dimensions */
- if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ if ( HDstrncmp( interlace, "INTERLACE_PIXEL",15 ) == 0 )
{
/* Number of color planes is defined as the third dimension */
dims[0] = height;
@@ -113,7 +124,7 @@ herr_t H5IMmake_image_24bit( hid_t loc_id,
dims[2] = IMAGE24_RANK;
}
else
- if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ if ( HDstrncmp( interlace, "INTERLACE_PLANE",15 ) == 0 )
{
/* Number of color planes is defined as the first dimension */
dims[0] = IMAGE24_RANK;
@@ -172,6 +183,10 @@ static herr_t find_palette(hid_t loc_id,
{
int ret = H5_ITER_CONT;
+ /* check the arguments */
+ if (name == NULL)
+ return -1;
+
/* Shut compiler up */
loc_id = loc_id; ainfo = ainfo; op_data = op_data;
@@ -179,7 +194,7 @@ static herr_t find_palette(hid_t loc_id,
* cause the iterator to immediately return that positive value,
* indicating short-circuit success
*/
- if(strcmp(name, "PALETTE") == 0)
+ if(HDstrncmp(name, "PALETTE",7) == 0)
ret = H5_ITER_STOP;
return ret;
@@ -250,6 +265,12 @@ herr_t H5IMget_image_info( hid_t loc_id,
int has_pal;
int has_attr;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+ if (interlace == NULL)
+ return -1;
+
/*assume initially we have no palettes attached*/
*npals = 0;
@@ -294,7 +315,7 @@ herr_t H5IMget_image_info( hid_t loc_id,
/* This is a 24 bit image */
{
- if ( strcmp( interlace, "INTERLACE_PIXEL" ) == 0 )
+ if ( HDstrncmp( interlace, "INTERLACE_PIXEL", 15 ) == 0 )
{
/* Number of color planes is defined as the third dimension */
*height = dims[0];
@@ -302,14 +323,14 @@ herr_t H5IMget_image_info( hid_t loc_id,
*planes = dims[2];
}
else
- if ( strcmp( interlace, "INTERLACE_PLANE" ) == 0 )
+ if ( HDstrncmp( interlace, "INTERLACE_PLANE", 15 ) == 0 )
{
/* Number of color planes is defined as the first dimension */
*planes = dims[0];
*height = dims[1];
*width = dims[2];
}
- else return -1;
+ else return -1;
}
else
/* This is a 8 bit image */
@@ -410,6 +431,10 @@ herr_t H5IMread_image( hid_t loc_id,
{
hid_t did;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -460,6 +485,10 @@ herr_t H5IMmake_palette( hid_t loc_id,
int has_pal;
+ /* check the arguments */
+ if (pal_name == NULL)
+ return -1;
+
/* Check if the dataset already exists */
has_pal = H5LTfind_dataset( loc_id, pal_name );
@@ -523,6 +552,13 @@ herr_t H5IMlink_palette( hid_t loc_id,
hsize_t dim_ref;
int ok_pal;
+
+ /* check the arguments */
+ if (image_name == NULL)
+ return -1;
+ if (pal_name == NULL)
+ return -1;
+
/* The image dataset may or may not have the attribute "PALETTE"
* First we try to open to see if it is already there; if not, it is created.
* If it exists, the array of references is extended to hold the reference
@@ -685,6 +721,12 @@ herr_t H5IMunlink_palette( hid_t loc_id,
H5T_class_t aclass;
int ok_pal, has_pal;
+ /* check the arguments */
+ if(image_name == NULL)
+ return -1;
+ if(pal_name == NULL)
+ return -1;
+
/* Try to find the palette dataset */
has_pal = H5LTfind_dataset( loc_id, pal_name );
@@ -780,6 +822,10 @@ herr_t H5IMget_npalettes( hid_t loc_id,
H5T_class_t aclass;
int has_pal;
+ /* check the arguments */
+ if(image_name == NULL)
+ return -1;
+
/*assume initially we have no palettes attached*/
*npals = 0;
@@ -875,6 +921,10 @@ herr_t H5IMget_palette_info( hid_t loc_id,
hid_t pal_space_id;
hsize_t pal_maxdims[2];
+ /* check the arguments */
+ if (image_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
return -1;
@@ -986,6 +1036,13 @@ herr_t H5IMget_palette( hid_t loc_id,
hobj_ref_t *refbuf; /* buffer to read references */
hid_t pal_id;
+ /* check the arguments */
+ if (image_name == NULL)
+ return -1;
+ if (pal_data == NULL)
+ return -1;
+
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, image_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1078,10 +1135,15 @@ herr_t H5IMis_image( hid_t loc_id,
hid_t did;
int has_class;
hid_t atid;
- hid_t aid;
- char attr_data[20];
+ hid_t aid = -1;
+ char* attr_data; /* Name of attribute */
+ hsize_t storage_size; /* Size of storage for attribute */
herr_t ret;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Assume initially fail condition */
ret = -1;
@@ -1106,17 +1168,32 @@ herr_t H5IMis_image( hid_t loc_id,
if((atid = H5Aget_type(aid)) < 0)
goto out;
- if(H5Tget_class(atid) < 0)
- goto out;
+ /* check to make sure attribute is a string */
+ if(H5T_STRING != H5Tget_class(atid))
+ goto out;
+
+ /* check to make sure string is null-terminated */
+ if(H5T_STR_NULLTERM != H5Tget_strpad(atid))
+ goto out;
+
+ /* allocate buffer large enough to hold string */
+ if((storage_size = H5Aget_storage_size(aid)) == 0)
+ goto out;
+
+ attr_data = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1);
+ if(attr_data == NULL)
+ goto out;
if(H5Aread(aid, atid, attr_data) < 0)
goto out;
- if(strcmp(attr_data, IMAGE_CLASS) == 0)
+ if(HDstrncmp(attr_data, IMAGE_CLASS, MIN(HDstrlen(IMAGE_CLASS),HDstrlen(attr_data))) == 0)
ret = 1;
else
ret = 0;
+ HDfree(attr_data);
+
if ( H5Tclose( atid ) < 0)
goto out;
@@ -1163,10 +1240,15 @@ herr_t H5IMis_palette( hid_t loc_id,
hid_t did;
int has_class;
hid_t atid;
- hid_t aid;
- char attr_data[20];
+ hid_t aid = -1;
+ char* attr_data; /* Name of attribute */
+ hsize_t storage_size; /* Size of storage for attribute */
herr_t ret;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Assume initially fail condition */
ret = -1;
@@ -1191,17 +1273,32 @@ herr_t H5IMis_palette( hid_t loc_id,
if((atid = H5Aget_type(aid)) < 0)
goto out;
- if(H5Tget_class(atid) < 0)
- goto out;
+ /* check to make sure attribute is a string */
+ if(H5T_STRING != H5Tget_class(atid))
+ goto out;
+
+ /* check to make sure string is null-terminated */
+ if(H5T_STR_NULLTERM != H5Tget_strpad(atid))
+ goto out;
+
+ /* allocate buffer large enough to hold string */
+ if((storage_size = H5Aget_storage_size(aid)) == 0)
+ goto out;
+
+ attr_data = (char*)HDmalloc( (size_t)storage_size * sizeof(char) + 1);
+ if(attr_data == NULL)
+ goto out;
if(H5Aread(aid, atid, attr_data) < 0)
goto out;
- if(strcmp(attr_data, PALETTE_CLASS) == 0)
+ if(HDstrncmp(attr_data, PALETTE_CLASS, MIN(HDstrlen(PALETTE_CLASS),HDstrlen(attr_data))) == 0)
ret = 1;
else
ret = 0;
+ HDfree(attr_data);
+
if ( H5Tclose( atid ) < 0)
goto out;
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index 6da097c..071b8a5 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -524,6 +524,10 @@ H5LT_make_dataset_numerical( hid_t loc_id,
{
hid_t did = -1, sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Create the data space for the dataset. */
if((sid = H5Screate_simple(rank, dims, NULL)) < 0)
return -1;
@@ -799,6 +803,10 @@ herr_t H5LTmake_dataset_string(hid_t loc_id,
hid_t tid = -1;
size_t size;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* create a string data type */
if((tid = H5Tcopy(H5T_C_S1)) < 0 )
goto out;
@@ -977,6 +985,10 @@ H5LT_read_dataset_numerical(hid_t loc_id, const char *dset_name, hid_t tid, void
{
hid_t did;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1168,6 +1180,10 @@ herr_t H5LTread_dataset_string( hid_t loc_id,
hid_t did = -1;
hid_t tid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1217,6 +1233,10 @@ herr_t H5LTget_dataset_ndims( hid_t loc_id,
hid_t did = -1;
hid_t sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* Open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1273,6 +1293,10 @@ herr_t H5LTget_dataset_info( hid_t loc_id,
hid_t tid = -1;
hid_t sid = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ return -1;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1346,6 +1370,10 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
*/
int ret = 0;
+ /* check the arguments */
+ if (name == NULL)
+ return ret;
+
/* Shut the compiler up */
loc_id = loc_id;
linfo = linfo;
@@ -1354,7 +1382,7 @@ find_dataset(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *op_d
* cause the iterator to immediately return that positive value,
* indicating short-circuit success
*/
- if(HDstrcmp(name, (char *)op_data) == 0)
+ if(HDstrncmp(name, (char *)op_data, HDstrlen((char *)op_data)) == 0)
ret = 1;
return ret;
@@ -1429,6 +1457,14 @@ herr_t H5LTset_attribute_string( hid_t loc_id,
int has_attr;
size_t attr_size;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+ if (attr_data == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1518,6 +1554,12 @@ herr_t H5LT_set_attribute_numerical( hid_t loc_id,
hsize_t dim_size=size;
int has_attr;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -1929,6 +1971,10 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
{
int ret = H5_ITER_CONT;
+ /* check the arguments */
+ if (name == NULL)
+ return H5_ITER_CONT;
+
/* Shut compiler up */
loc_id = loc_id; ainfo = ainfo;
@@ -1936,7 +1982,7 @@ find_attr(hid_t loc_id, const char *name, const H5A_info_t *ainfo,
* cause the iterator to immediately return that positive value,
* indicating short-circuit success
*/
- if(HDstrcmp(name, (char *)op_data) == 0)
+ if(HDstrncmp(name, (char *)op_data, HDstrlen((char *)op_data)) == 0)
ret = H5_ITER_STOP;
return ret;
@@ -2021,6 +2067,12 @@ herr_t H5LTget_attribute_ndims( hid_t loc_id,
hid_t sid;
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -2088,6 +2140,12 @@ herr_t H5LTget_attribute_info( hid_t loc_id,
hid_t sid;
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -2163,6 +2221,10 @@ hid_t H5LTtext_to_dtype(const char *text, H5LT_lang_t lang_type)
{
hid_t type_id;
+ /* check the arguments */
+ if (text == NULL)
+ return -1;
+
if(lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG)
goto out;
@@ -2206,6 +2268,8 @@ out:
static char*
realloc_and_append(hbool_t _no_user_buf, size_t *len, char *buf, char *str_to_add)
{
+ size_t size_str_to_add, size_str;
+
if(_no_user_buf) {
/* If the buffer isn't big enough, reallocate it. Otherwise, go to do strcat. */
if(str_to_add && ((ssize_t)(*len - (HDstrlen(buf) + HDstrlen(str_to_add) + 1)) < LIMIT)) {
@@ -2220,8 +2284,25 @@ realloc_and_append(hbool_t _no_user_buf, size_t *len, char *buf, char *str_to_ad
if(!buf)
goto out;
- if(str_to_add)
- HDstrcat(buf, str_to_add);
+ if(str_to_add) {
+ /* find the size of the buffer to add */
+ size_str_to_add = HDstrlen(str_to_add);
+ /* find the size of the current buffer */
+ size_str = HDstrlen(buf);
+
+ /* Check to make sure the appended string does not
+ * extend past the allocated buffer; if it does then truncate the string
+ */
+ if(size_str < *len - 1) {
+ if( size_str + size_str_to_add < *len - 1) {
+ HDstrncat(buf, str_to_add, size_str_to_add);
+ } else {
+ HDstrncat(buf, str_to_add, (*len - 1) - size_str);
+ }
+ } else {
+ buf[*len-1] = '\0'; /* buffer is full, null terminate */
+ }
+ }
return buf;
@@ -3020,6 +3101,12 @@ herr_t H5LTget_attribute_string( hid_t loc_id,
/* identifiers */
hid_t obj_id;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if ((obj_id = H5Oopen( loc_id, obj_name, H5P_DEFAULT)) < 0)
return -1;
@@ -3440,6 +3527,12 @@ static herr_t H5LT_get_attribute_mem(hid_t loc_id,
hid_t obj_id = -1;
hid_t attr_id = -1;
+ /* check the arguments */
+ if (obj_name == NULL)
+ return -1;
+ if (attr_name == NULL)
+ return -1;
+
/* Open the object */
if((obj_id = H5Oopen(loc_id, obj_name, H5P_DEFAULT)) < 0)
goto out;
@@ -3619,6 +3712,12 @@ H5LTpath_valid(hid_t loc_id, const char *path, hbool_t check_object_valid)
/* Initialize */
ret_value = FALSE;
+ /* check the arguments */
+ if (path == NULL) {
+ ret_value = FAIL;
+ goto done;
+ }
+
/* Find the type of loc_id */
if((obj_type = H5Iget_type(loc_id)) == H5I_BADID) {
ret_value = FAIL;
diff --git a/hl/src/H5PT.c b/hl/src/H5PT.c
index d3a03cd..7a0bc20 100644
--- a/hl/src/H5PT.c
+++ b/hl/src/H5PT.c
@@ -84,6 +84,11 @@ hid_t H5PTcreate_fl ( hid_t loc_id,
hsize_t maxdims[1];
hid_t ret_value;
+ /* check the arguments */
+ if (dset_name == NULL) {
+ goto out;
+ }
+
/* Register the packet table ID type if this is the first table created */
if(H5PT_ptable_id_type < 0)
if((H5PT_ptable_id_type = H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
@@ -178,6 +183,11 @@ hid_t H5PTcreate_vl ( hid_t loc_id,
hid_t ret_value=H5I_BADID;
hid_t vltype;
+ /* check the arguments */
+ if (dset_name == NULL) {
+ goto out;
+ }
+
/* Create a variable length type that uses single bytes as its base type */
vltype = H5Tvlen_create(H5T_NATIVE_UCHAR);
if(vltype < 0)
@@ -232,6 +242,11 @@ hid_t H5PTopen( hid_t loc_id,
hid_t ret_value;
hsize_t dims[1];
+ /* check the arguments */
+ if (dset_name == NULL) {
+ goto out;
+ }
+
/* Register the packet table ID type if this is the first table created */
if( H5PT_ptable_id_type < 0)
if((H5PT_ptable_id_type = H5Iregister_type((size_t)H5PT_HASH_TABLE_SIZE, 0, (H5I_free_t)H5PT_free_id)) < 0)
diff --git a/hl/src/H5TB.c b/hl/src/H5TB.c
index a1456ea..1ca41a8 100644
--- a/hl/src/H5TB.c
+++ b/hl/src/H5TB.c
@@ -94,6 +94,17 @@ herr_t H5TBmake_table(const char *table_title,
hsize_t i;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (table_title == NULL) {
+ goto out;
+ }
+ if (dset_name == NULL) {
+ goto out;
+ }
+ if (field_names == NULL) {
+ goto out;
+ }
+
dims[0] = nrecords;
dims_chunk[0] = chunk_size;
@@ -290,6 +301,10 @@ herr_t H5TBappend_records(hid_t loc_id,
hsize_t nfields;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* get the original number of records and fields */
if(H5TBget_table_info(loc_id, dset_name, &nfields, &nrecords_orig) < 0)
goto out;
@@ -360,6 +375,10 @@ herr_t H5TBwrite_records(hid_t loc_id,
hsize_t dims[1];
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -459,6 +478,12 @@ herr_t H5TBwrite_fields_name(hid_t loc_id,
size_t size_native;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+ if (field_names == NULL)
+ goto out;
+
/* create xfer properties to preserve initialized data */
if((preserve_id = H5Pcreate(H5P_DATASET_XFER)) < 0)
goto out;
@@ -616,6 +641,10 @@ herr_t H5TBwrite_fields_index(hid_t loc_id,
char *member_name = NULL;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* create xfer properties to preserve initialized data */
if((preserve_id = H5Pcreate(H5P_DATASET_XFER)) < 0)
goto out;
@@ -773,6 +802,10 @@ herr_t H5TBread_table(hid_t loc_id,
hsize_t dims[1];
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -846,6 +879,10 @@ herr_t H5TBread_records(hid_t loc_id,
hsize_t nfields;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* get the number of records and fields */
if(H5TBget_table_info(loc_id, dset_name, &nfields, &nrecords_orig) < 0)
goto out;
@@ -922,6 +959,13 @@ herr_t H5TBread_fields_name(hid_t loc_id,
hssize_t i, j;
herr_t ret_val = -1;
+
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+ if (field_names == NULL)
+ goto out;
+
/* open the dataset */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -938,7 +982,7 @@ herr_t H5TBread_fields_name(hid_t loc_id,
if((mem_type_id = H5Tcreate(H5T_COMPOUND, type_size)) < 0)
goto out;
- /* iterate tru the members */
+ /* iterate through the members */
for(i = 0, j = 0; i < nfields; i++) {
/* get the member name */
if(NULL == (member_name = H5Tget_member_name(ftype_id, (unsigned)i)))
@@ -984,6 +1028,10 @@ herr_t H5TBread_fields_name(hid_t loc_id,
member_name = NULL;
} /* end for */
+ /* check to make sure field was found, no reason to continue if it does not exist */
+ if(j == 0)
+ goto out;
+
/* get the dataspace handle */
if((sid = H5Dget_space(did)) < 0)
goto out;
@@ -1074,6 +1122,10 @@ herr_t H5TBread_fields_index(hid_t loc_id,
char *member_name = NULL;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -1231,6 +1283,11 @@ herr_t H5TBdelete_record(hid_t loc_id,
unsigned char *tmp_buf = NULL;
herr_t ret_val = -1;
+
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/*-------------------------------------------------------------------------
* first we get information about type size and offsets on disk
*-------------------------------------------------------------------------
@@ -1390,6 +1447,10 @@ herr_t H5TBinsert_record(hid_t loc_id,
unsigned char *tmp_buf = NULL;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/*-------------------------------------------------------------------------
* read the records after the inserted one(s)
*-------------------------------------------------------------------------
@@ -1541,6 +1602,12 @@ herr_t H5TBadd_records_from(hid_t loc_id,
unsigned char *tmp_buf = NULL;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name1 == NULL)
+ goto out;
+ if (dset_name2 == NULL)
+ goto out;
+
/*-------------------------------------------------------------------------
* first we get information about type size and offsets on disk
*-------------------------------------------------------------------------
@@ -1688,6 +1755,14 @@ herr_t H5TBcombine_tables(hid_t loc_id1,
htri_t has_fill;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name1 == NULL)
+ goto out;
+ if (dset_name2 == NULL)
+ goto out;
+ if (dset_name3 == NULL)
+ goto out;
+
/*-------------------------------------------------------------------------
* first we get information about type size and offsets on disk
*-------------------------------------------------------------------------
@@ -2043,6 +2118,12 @@ herr_t H5TBinsert_field(hid_t loc_id,
hbool_t inserted;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+ if (field_name == NULL)
+ goto out;
+
/* get the number of records and fields */
if(H5TBget_table_info(loc_id, dset_name, &nfields, &nrecords) < 0)
goto out;
@@ -2451,6 +2532,13 @@ herr_t H5TBdelete_field(hid_t loc_id,
htri_t has_fill = FALSE;
herr_t ret_val = -1;
+
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+ if (field_name == NULL)
+ goto out;
+
/* get the number of records and fields */
if(H5TBget_table_info(loc_id, dset_name, &nfields, &nrecords) < 0)
goto out;
@@ -2859,6 +2947,7 @@ out:
herr_t H5TBAget_title(hid_t loc_id,
char *table_title)
{
+
/* Get the TITLE attribute */
if(H5LT_get_attribute_disk(loc_id, "TITLE", table_title) < 0)
return -1;
@@ -2894,6 +2983,10 @@ htri_t H5TBAget_fill(hid_t loc_id,
htri_t has_fill = FALSE;
htri_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* get the number of records and fields */
if(H5TBget_table_info(loc_id, dset_name, &nfields, &nrecords) < 0)
goto out;
@@ -2962,6 +3055,10 @@ herr_t H5TBget_table_info(hid_t loc_id,
int num_members;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -3049,6 +3146,10 @@ herr_t H5TBget_field_info(hid_t loc_id,
hssize_t i;
herr_t ret_val = -1;
+ /* check the arguments */
+ if (dset_name == NULL)
+ goto out;
+
/* open the dataset. */
if((did = H5Dopen2(loc_id, dset_name, H5P_DEFAULT)) < 0)
goto out;
@@ -3153,6 +3254,12 @@ hbool_t H5TB_find_field(const char *field, const char *field_list)
const char *start = field_list;
const char *end;
+ /* check the arguments */
+ if (field == NULL)
+ return FALSE;
+ if (field_list == NULL)
+ return FALSE;
+
while((end = HDstrstr(start, ",")) != 0) {
ptrdiff_t count = end - start;
@@ -3161,7 +3268,7 @@ hbool_t H5TB_find_field(const char *field, const char *field_list)
start = end + 1;
} /* end while */
- if(HDstrcmp(start, field) == 0)
+ if(HDstrncmp(start, field, HDstrlen(field)) == 0)
return TRUE;
return FALSE;
diff --git a/hl/test/test_lite.c b/hl/test/test_lite.c
index 576d594..9a15957 100644
--- a/hl/test/test_lite.c
+++ b/hl/test/test_lite.c
@@ -1238,6 +1238,41 @@ static int test_strings(void)
}
HDfree(dt_str);
+ /* Length of the character buffer is larger then needed */
+ str_len = str_len + 10;
+ if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
+ goto out;
+
+ if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
+ HDfree(dt_str);
+ goto out;
+ }
+ if(HDstrncmp(dt_str, "H5T_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }", str_len-1)) {
+ printf("dt=\n%s\n", dt_str);
+ HDfree(dt_str);
+ goto out;
+ }
+
+ /* Length of the character buffer is smaller then needed */
+ str_len = 21;
+ if(NULL==(dt_str = (char*)HDcalloc(str_len, sizeof(char))))
+ goto out;
+
+ if(H5LTdtype_to_text(dtype, dt_str, H5LT_DDL, &str_len)<0) {
+ HDfree(dt_str);
+ goto out;
+ }
+ /* check the truncated string */
+ if(strlen(dt_str) != str_len-1) goto out;
+ str_len = strlen(dt_str);
+ if(HDstrncmp(dt_str, "H5T_STRING {\n STRSIZE H5T_VARIABLE;\n STRPAD H5T_STR_NULLPAD;\n CSET H5T_CSET_ASCII;\n CTYPE H5T_C_S1;\n }", str_len)) {
+ printf("dt=\n%s\n", dt_str);
+ HDfree(dt_str);
+ goto out;
+ }
+
+ HDfree(dt_str);
+
if(H5Tclose(dtype)<0)
goto out;
@@ -1245,6 +1280,9 @@ static int test_strings(void)
return 0;
out:
+ if(dt_str)
+ HDfree(dt_str);
+
H5_FAILED();
return -1;
}
diff --git a/hl/test/test_table.c b/hl/test/test_table.c
index 4b62ac5..4eb5819 100644
--- a/hl/test/test_table.c
+++ b/hl/test/test_table.c
@@ -1195,14 +1195,19 @@ static int test_table(hid_t fid, int do_write)
goto out;
}
- /* read the "Pressure" field */
start = 0;
nrecords = NRECORDS;
+
+ /* read an invalid field, should fail */
+ if ( H5TBread_fields_name(fid,"table10","DoesNotExist",start,nrecords,
+ sizeof(float),0,field_sizes_pre,pressure_out) >=0)
+ goto out;
+
+ /* read the "Pressure" field */
if ( H5TBread_fields_name(fid,"table10","Pressure",start,nrecords,
sizeof(float),0,field_sizes_pre,pressure_out)<0)
goto out;
-
/* Compare the extracted table with the initial values */
for( i = 0; i < NRECORDS; i++ )
{