summaryrefslogtreecommitdiffstats
path: root/test/dtypes.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-07-30 18:06:32 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-07-30 18:06:32 (GMT)
commiteff803f8249485e8b1fdb5c71197314f0527c995 (patch)
tree46163e26a5b0be38e839f8f195b1821ba25f86d6 /test/dtypes.c
parent7fe87a24722f991ffc030782cd42d24df00dbace (diff)
downloadhdf5-eff803f8249485e8b1fdb5c71197314f0527c995.zip
hdf5-eff803f8249485e8b1fdb5c71197314f0527c995.tar.gz
hdf5-eff803f8249485e8b1fdb5c71197314f0527c995.tar.bz2
[svn-r19156] Description:
Bring revisions from Coverity branch back to trunk: r19044: Coverity #449 - Line 1560 called function H5O_chunk_protect for 2 pointers to allocate. But when there's failure on the second one, the first wasn't freed (H5O_chunk_unprotect). We fixed it by freeing the pointers when an error happens. r19045: Fixed coverity issue # 319. Free sec_node in done if it is not NULL. r19046: Add intended but missing assignments to initialize pointers to NULL (coverity issue fixes). r19049: Hdf5_1_8_coverity branch was recreated from hdf5_1_8 branch in revision 18839 without fix for Coverity issue #84 having been propagated to the hdf5_1_8 branch. This revision adds the fix again. r19060: added parentheses to see if they will keep subversion from getting confused r19061: Fix coverity item 139. Fixed incorrect condition for freeing buffer on error. Fix coverity items 20 and 21. Removed unused NTESTS facility from dtypes.c. Cleanup in H5Shyper.c. r19062: Fix coverity item 450. Check to see if chk_proxy has been allocated before attempting to free it. Fix coverity item 454. Check to see if allocation of buf failed in H5D_fill_refill_vl. Fix coverity items 455-457. Initilize hid_t's to -1, check their value before attempting to close them, and check if the close failed. r19063: New fix to address coverity issue #84. Check that pointers in H5Z_xform_find_type are not NULL before passing them to H5T_cmp. Tested on: Mac OS X/32 10.6.4 (amazon) w/debug & production (Too minor to require h5committest)
Diffstat (limited to 'test/dtypes.c')
-rw-r--r--test/dtypes.c129
1 files changed, 55 insertions, 74 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 3af2b8a..e42c243 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -25,9 +25,6 @@
#include "h5test.h"
#include "H5Iprivate.h" /* For checking that datatype id's don't leak */
-/* Number of times to run each test */
-#define NTESTS 1
-
/* Number of elements in each test */
#define NTESTELEM 100000
@@ -184,64 +181,64 @@ test_classes(void)
hid_t memb_id; /* Compound member datatype */
H5T_class_t memb_cls;
H5T_class_t tcls;
- unsigned int nmembs, i;
+ int nmembs;
+ unsigned u;
TESTING("H5Tget_class()");
/*-------------------------------------------------------------
* Check class of some atomic types.
*-----------------------------------------------------------*/
- if ((tcls=H5Tget_class(H5T_NATIVE_INT)) < 0) TEST_ERROR
- if (H5T_INTEGER!=tcls) TEST_ERROR
+ if((tcls = H5Tget_class(H5T_NATIVE_INT)) < 0) TEST_ERROR
+ if(H5T_INTEGER != tcls) TEST_ERROR
- if ((tcls=H5Tget_class(H5T_NATIVE_DOUBLE)) < 0) TEST_ERROR
- if (H5T_FLOAT!=tcls) TEST_ERROR
+ if((tcls = H5Tget_class(H5T_NATIVE_DOUBLE)) < 0) TEST_ERROR
+ if(H5T_FLOAT != tcls) TEST_ERROR
/* Create a VL datatype of char. It should be a VL, not a string class. */
- if((vlc_id=H5Tvlen_create(H5T_NATIVE_CHAR)) < 0) TEST_ERROR
+ if((vlc_id = H5Tvlen_create(H5T_NATIVE_CHAR)) < 0) TEST_ERROR
/* Make certain that the correct classes can be detected */
- if ((tcls=H5Tget_class(vlc_id)) < 0) TEST_ERROR
- if (H5T_VLEN!=tcls) TEST_ERROR
+ if((tcls = H5Tget_class(vlc_id)) < 0) TEST_ERROR
+ if(H5T_VLEN != tcls) TEST_ERROR
/* Make certain that an incorrect class is not detected */
- if (H5T_STRING==tcls) TEST_ERROR
+ if(H5T_STRING == tcls) TEST_ERROR
/* Create a VL string. It should be a string, not a VL class. */
- if((vls_id=H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
+ if((vls_id = H5Tcopy(H5T_C_S1)) < 0) TEST_ERROR
if(H5Tset_size(vls_id, H5T_VARIABLE) < 0) TEST_ERROR;
/* Make certain that the correct classes can be detected */
- if ((tcls=H5Tget_class(vls_id)) < 0) TEST_ERROR
- if (H5T_STRING!=tcls) TEST_ERROR
+ if((tcls = H5Tget_class(vls_id)) < 0) TEST_ERROR
+ if(H5T_STRING != tcls) TEST_ERROR
/* Make certain that an incorrect class is not detected */
- if (H5T_VLEN==tcls) TEST_ERROR
+ if(H5T_VLEN == tcls) TEST_ERROR
/*-------------------------------------------------------------
* Check class for member types of compound type.
*-----------------------------------------------------------*/
/* Create a compound datatype and insert some complex types */
- if ((cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex))) < 0) TEST_ERROR
- if (H5Tinsert(cmpd_id, "vl_c", HOFFSET(struct complex, vl_c), vlc_id) < 0) TEST_ERROR
- if (H5Tinsert(cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), vls_id) < 0) TEST_ERROR
+ if((cmpd_id = H5Tcreate(H5T_COMPOUND, sizeof(struct complex))) < 0) TEST_ERROR
+ if(H5Tinsert(cmpd_id, "vl_c", HOFFSET(struct complex, vl_c), vlc_id) < 0) TEST_ERROR
+ if(H5Tinsert(cmpd_id, "vl_s", HOFFSET(struct complex, vl_s), vls_id) < 0) TEST_ERROR
- nmembs = H5Tget_nmembers(cmpd_id);
+ if((nmembs = H5Tget_nmembers(cmpd_id)) < 0) TEST_ERROR
- for (i=0;i<nmembs;i++)
- {
+ for(u = 0; u < (unsigned)nmembs; u++) {
/* Get member type ID */
- if((memb_id = H5Tget_member_type(cmpd_id, i)) < 0) TEST_ERROR
+ if((memb_id = H5Tget_member_type(cmpd_id, u)) < 0) TEST_ERROR
/* Get member type class */
- if((memb_cls = H5Tget_member_class (cmpd_id, i)) < 0) TEST_ERROR
+ if((memb_cls = H5Tget_member_class (cmpd_id, u)) < 0) TEST_ERROR
/* Verify member class */
- if(H5Tdetect_class (memb_id, memb_cls) < 0) TEST_ERROR
+ if(H5Tdetect_class(memb_id, memb_cls) < 0) TEST_ERROR
/* Close member type ID */
if(H5Tclose(memb_id) < 0) TEST_ERROR
- }
+ } /* end for */
/* Close datatypes */
if(H5Tclose(cmpd_id) < 0) TEST_ERROR
@@ -2315,7 +2312,7 @@ test_compound_13(void)
float y;
};
struct s1 data_out, data_in;
- hid_t fileid, grpid, typeid, array1_tid, spaceid, attid;
+ hid_t fileid, grpid, dtypeid, array1_tid, spaceid, attid;
hid_t fapl_id;
hsize_t dims[1] = {COMPOUND13_ARRAY_SIZE + 1};
char filename[1024];
@@ -2340,24 +2337,24 @@ test_compound_13(void)
if((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* Create a compound type. */
- if((typeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) FAIL_STACK_ERROR
+ if((dtypeid = H5Tcreate(H5T_COMPOUND, sizeof(struct s1))) < 0) FAIL_STACK_ERROR
if((array1_tid = H5Tarray_create2(H5T_NATIVE_UCHAR, 1, dims)) < 0) FAIL_STACK_ERROR
- if(H5Tinsert(typeid, "x", HOFFSET(struct s1, x), array1_tid) < 0) FAIL_STACK_ERROR
- if(H5Tinsert(typeid, "y", HOFFSET(struct s1, y), H5T_NATIVE_FLOAT) < 0) FAIL_STACK_ERROR
+ if(H5Tinsert(dtypeid, "x", HOFFSET(struct s1, x), array1_tid) < 0) FAIL_STACK_ERROR
+ if(H5Tinsert(dtypeid, "y", HOFFSET(struct s1, y), H5T_NATIVE_FLOAT) < 0) FAIL_STACK_ERROR
/* Create a space. */
if((spaceid = H5Screate(H5S_SCALAR)) < 0) FAIL_STACK_ERROR
/* Create an attribute of this compound type. */
- if((attid = H5Acreate2(grpid, COMPOUND13_ATTR_NAME, typeid, spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
+ if((attid = H5Acreate2(grpid, COMPOUND13_ATTR_NAME, dtypeid, spaceid, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* Write some data. */
- if(H5Awrite(attid, typeid, &data_out) < 0) FAIL_STACK_ERROR
+ if(H5Awrite(attid, dtypeid, &data_out) < 0) FAIL_STACK_ERROR
/* Release all resources. */
if(H5Aclose(attid) < 0) FAIL_STACK_ERROR
if(H5Tclose(array1_tid) < 0) FAIL_STACK_ERROR
- if(H5Tclose(typeid) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(dtypeid) < 0) FAIL_STACK_ERROR
if(H5Sclose(spaceid) < 0) FAIL_STACK_ERROR
if(H5Gclose(grpid) < 0) FAIL_STACK_ERROR
if(H5Fclose(fileid) < 0) FAIL_STACK_ERROR
@@ -2367,11 +2364,11 @@ test_compound_13(void)
if((fileid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
if((grpid = H5Gopen2(fileid, "/", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
if((attid = H5Aopen(grpid, COMPOUND13_ATTR_NAME, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
- if((typeid = H5Aget_type(attid)) < 0) FAIL_STACK_ERROR
- if(H5Tget_class(typeid) != H5T_COMPOUND) FAIL_STACK_ERROR
- if(HOFFSET(struct s1, x) != H5Tget_member_offset(typeid, 0)) TEST_ERROR
- if(HOFFSET(struct s1, y) != H5Tget_member_offset(typeid, 1)) TEST_ERROR
- if(H5Aread(attid, typeid, &data_in) < 0) FAIL_STACK_ERROR
+ if((dtypeid = H5Aget_type(attid)) < 0) FAIL_STACK_ERROR
+ if(H5Tget_class(dtypeid) != H5T_COMPOUND) FAIL_STACK_ERROR
+ if(HOFFSET(struct s1, x) != H5Tget_member_offset(dtypeid, 0)) TEST_ERROR
+ if(HOFFSET(struct s1, y) != H5Tget_member_offset(dtypeid, 1)) TEST_ERROR
+ if(H5Aread(attid, dtypeid, &data_in) < 0) FAIL_STACK_ERROR
/* Check the data. */
for (u = 0; u < COMPOUND13_ARRAY_SIZE + 1; u++)
@@ -2380,7 +2377,7 @@ test_compound_13(void)
/* Release all resources. */
if(H5Aclose(attid) < 0) FAIL_STACK_ERROR
- if(H5Tclose(typeid) < 0) FAIL_STACK_ERROR
+ if(H5Tclose(dtypeid) < 0) FAIL_STACK_ERROR
if(H5Gclose(grpid) < 0) FAIL_STACK_ERROR
if(H5Fclose(fileid) < 0) FAIL_STACK_ERROR
@@ -4049,7 +4046,7 @@ test_conv_str_2(void)
char *buf = NULL, s[80];
hid_t c_type = -1;
hid_t f_type = -1;
- const size_t nelmts = NTESTELEM, ntests=NTESTS;
+ const size_t nelmts = NTESTELEM;
size_t i, j, nchars;
int ret_value = 1;
@@ -4068,19 +4065,14 @@ test_conv_str_2(void)
} /* end for */
/* Do the conversions */
- for(i = 0; i < ntests; i++) {
- if(ntests > 1)
- sprintf(s, "Testing random string conversion speed (test %d/%d)", (int)(i + 1), (int)ntests);
- else
- sprintf(s, "Testing random string conversion speed");
- printf("%-70s", s);
- HDfflush(stdout);
- if(H5Tconvert(c_type, f_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
- goto error;
- if(H5Tconvert(f_type, c_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
- goto error;
- PASSED();
- } /* end for */
+ sprintf(s, "Testing random string conversion speed");
+ printf("%-70s", s);
+ HDfflush(stdout);
+ if(H5Tconvert(c_type, f_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
+ goto error;
+ if(H5Tconvert(f_type, c_type, nelmts, buf, NULL, H5P_DEFAULT) < 0)
+ goto error;
+ PASSED();
ret_value = 0;
@@ -4232,7 +4224,6 @@ static int
test_conv_enum_1(void)
{
const size_t nelmts=NTESTELEM;
- const int ntests=NTESTS;
int i, val, *buf=NULL;
hid_t t1 = -1;
hid_t t2 = -1;
@@ -4257,27 +4248,17 @@ test_conv_enum_1(void)
buf[u] = HDrand() % 26;
/* Conversions */
- for(i = 0; i < ntests; i++) {
- if(ntests > 1)
- sprintf(s, "Testing random enum conversion O(N) (test %d/%d)", i + 1, ntests);
- else
- sprintf(s, "Testing random enum conversion O(N)");
- printf("%-70s", s);
- HDfflush(stdout);
- if(H5Tconvert(t1, t2, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
- PASSED();
- } /* end for */
+ sprintf(s, "Testing random enum conversion O(N)");
+ printf("%-70s", s);
+ HDfflush(stdout);
+ if(H5Tconvert(t1, t2, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
+ PASSED();
- for(i = 0; i < ntests; i++) {
- if(ntests > 1)
- sprintf(s, "Testing random enum conversion O(N log N) (test %d/%d)", i + 1, ntests);
- else
- sprintf(s, "Testing random enum conversion O(N log N)");
- printf("%-70s", s);
- HDfflush(stdout);
- if(H5Tconvert(t2, t1, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
- PASSED();
- }
+ sprintf(s, "Testing random enum conversion O(N log N)");
+ printf("%-70s", s);
+ HDfflush(stdout);
+ if(H5Tconvert(t2, t1, nelmts, buf, NULL, H5P_DEFAULT) < 0) goto error;
+ PASSED();
ret_value = 0;