summaryrefslogtreecommitdiffstats
path: root/test/dtypes.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:00:00 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-01-23 07:00:00 (GMT)
commitbb25c85e794449d3bf59d8811e53288569161790 (patch)
treee6c37cf6f8bba9323540ddddb70300b43351d88f /test/dtypes.c
parentfcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (diff)
downloadhdf5-bb25c85e794449d3bf59d8811e53288569161790.zip
hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.gz
hdf5-bb25c85e794449d3bf59d8811e53288569161790.tar.bz2
[svn-r18159] Description:
Bring Coverity fixes from 1/22/10 session to trunk: r18137: 219: Initialized hid_t to -1 and added close to error block. 189-191: Initialized line to NULL and added free line, and close fp to error block. r18138: 19: Moved code block for printing that the number of enums is empty to the error block. (Would never have been executed otherwise) r18139: Fix coverity item 58. Moved code related to displaying the parent of a repeated group to the else(isRoot) section, as the root group has no parent. r18140: 218: Initialized ret_value variable to -1. Because of throw Exception in default case of switch, the coverity problem would not have executed anyway. Good pratice is to initialize variables. r18141: Fix coverity item 92. Added code to H5E_register_class to free cls in case of an error. r18142: Fix coverity item 91. Added code to H5E_create_msg to free msg in case of an error. r18143: fixed issue 14, took away "if" and used #ifndef_xxx. r18144: Fix coverity item 110. Added code to H5Eget_minor to free msg_str in case of an error. r18145: fixed coverity #18 removed "aligned", it is always NULL. r18146: Fix coverity item 109. Added code to H5Eget_major to free msg_str in case of an error. r18147: Fixed coverity #81 and #82, Check for bad pointer(s), but can't issue error, just leave r18148: Fix coverity item 97. Added code to H5FD_fapl_open to free copied_driver_info in case of an error. r18149: Fix coverity item 96. Added code to H5FD_dxpl_open to free copied_driver_info in case of an error. r18150: Fix Coverity issue #29: Protected cache_ptr dereferences with "if(pass)" block r18151: Fix coverity item 93. Added code to H5FL_fac_init to free factory and new_node in case of an error. r18152: Fix coverity items 98 and 99. Added code free allocated space in case of error. r18155: 124: Freed head pointer before jumping to done. There was no error handling block and normal exit used same path out. 120-123: Freed list of lists in error handling block. r18156: Fix coverity issues 179, 180, 181, 182, 183, 184, 186, 320, 407. These were resource leak issues where allocated memory was not freed, generally in the case of tests that failed. Tested on: Mac OS X/32 10.6.2 (amazon) debug & production
Diffstat (limited to 'test/dtypes.c')
-rw-r--r--test/dtypes.c148
1 files changed, 63 insertions, 85 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 020a603..f32afe5 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -515,39 +515,37 @@ test_compound_1(void)
H5T_str_t strpad;
H5T_order_t order;
H5T_sign_t sign;
- char* tag;
+ char *tag = NULL;
int offset;
herr_t ret;
+ int retval = 1;
TESTING("compound datatypes");
/* Create the empty type */
- if ((complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t))) < 0) goto error;
+ if ((complex_id = H5Tcreate(H5T_COMPOUND, sizeof(complex_t))) < 0)
+ goto error;
/* Attempt to add the new compound datatype as a field within itself */
H5E_BEGIN_TRY {
ret=H5Tinsert(complex_id, "compound", 0, complex_id);
} H5E_END_TRY;
if (ret>=0) {
- H5_FAILED();
- printf("Inserted compound datatype into itself?\n");
- goto error;
+ FAIL_PUTS_ERROR("Inserted compound datatype into itself?");
} /* end if */
/* Add a couple fields */
- if (H5Tinsert(complex_id, "real", HOFFSET(complex_t, re),
- H5T_NATIVE_DOUBLE) < 0) goto error;
- if (H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im),
- H5T_NATIVE_DOUBLE) < 0) goto error;
+ if(H5Tinsert(complex_id, "real", HOFFSET(complex_t, re), H5T_NATIVE_DOUBLE) < 0)
+ goto error;
+ if(H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im), H5T_NATIVE_DOUBLE) < 0)
+ goto error;
/* Test some functions that aren't supposed to work for compound type */
H5E_BEGIN_TRY {
size=H5Tget_precision(complex_id);
} H5E_END_TRY;
if (size>0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
size = 128;
@@ -555,108 +553,89 @@ test_compound_1(void)
ret = H5Tset_precision(complex_id, size);
} H5E_END_TRY;
if (ret>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
ret = H5Tget_pad(complex_id, &lsb, &msb);
} H5E_END_TRY;
if (ret>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
size = H5Tget_ebias(complex_id);
} H5E_END_TRY;
if (size>0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
lsb = H5Tget_inpad(complex_id);
} H5E_END_TRY;
if (lsb>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
cset = H5Tget_cset(complex_id);
} H5E_END_TRY;
if (cset>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
strpad = H5Tget_strpad(complex_id);
} H5E_END_TRY;
if (strpad>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
offset = H5Tget_offset(complex_id);
} H5E_END_TRY;
if (offset>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
order = H5Tget_order(complex_id);
} H5E_END_TRY;
if (order>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
sign = H5Tget_sign(complex_id);
} H5E_END_TRY;
if (sign>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
tag = H5Tget_tag(complex_id);
} H5E_END_TRY;
if (tag) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(complex_id);
} H5E_END_TRY;
if (super>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
- if (H5Tclose (complex_id) < 0) goto error;
+ if (H5Tclose (complex_id) < 0)
+ goto error;
PASSED();
- return 0;
+ retval = 0;
- error:
- return 1;
+error:
+ if(tag)
+ HDfree(tag);
+ return retval;
}
@@ -1068,6 +1047,7 @@ test_compound_5(void)
dst_type_t *dst;
void *buf = calloc(2, sizeof(dst_type_t));
void *bkg = calloc(2, sizeof(dst_type_t));
+ int retval = 1;
#if 1
TESTING("optimized struct converter");
@@ -1124,14 +1104,17 @@ test_compound_5(void)
src[1].coll_ids[2]!=dst[1].coll_ids[2] ||
src[1].coll_ids[3]!=dst[1].coll_ids[3]) {
H5_FAILED();
- return 1;
+ } else {
+ PASSED();
+ retval = 0;
}
/* Free memory buffers */
- free(buf);
- free(bkg);
- PASSED();
- return 0;
+ if(buf)
+ HDfree(buf);
+ if(bkg)
+ HDfree(bkg);
+ return retval;
}
@@ -2054,10 +2037,11 @@ test_compound_11(void)
hid_t big_tid, little_tid; /* Datatype IDs for type conversion */
hid_t big_tid2, little_tid2; /* Datatype IDs for type conversion */
hid_t opaq_src_tid, opaq_dst_tid; /* Datatype IDs for type conversion */
- void *buf, /* Conversion buffer */
- *buf_orig, /* Copy of original conversion buffer */
- *bkg; /* Background buffer */
+ void *buf = NULL; /* Conversion buffer */
+ void *buf_orig = NULL; /* Copy of original conversion buffer */
+ void *bkg = NULL; /* Background buffer */
size_t u; /* Local index variable */
+ int retval = 1;
TESTING("registering type conversion routine with compound conversions");
@@ -2216,18 +2200,21 @@ test_compound_11(void)
if(H5Tclose(opaq_src_tid) < 0) TEST_ERROR
if(H5Tclose(little_tid2) < 0) TEST_ERROR
if(H5Tclose(big_tid2) < 0) TEST_ERROR
- HDfree(bkg);
- HDfree(buf_orig);
- HDfree(buf);
if(H5Tclose(little_tid) < 0) TEST_ERROR
if(H5Tclose(big_tid) < 0) TEST_ERROR
if(H5Tclose(var_string_tid) < 0) TEST_ERROR
PASSED();
- return 0;
+ retval = 0;
- error:
- return 1;
+error:
+ if(buf)
+ HDfree(buf);
+ if(buf_orig)
+ HDfree(buf_orig);
+ if(bkg)
+ HDfree(bkg);
+ return retval;
}
@@ -4133,7 +4120,7 @@ test_conv_str_3(void)
int size;
H5T_pad_t inpad;
H5T_sign_t sign;
- char* tag;
+ char *tag = NULL;
herr_t ret;
TESTING("some type functions for string");
@@ -4163,63 +4150,54 @@ test_conv_str_3(void)
ret=H5Tset_precision(type, nelmts);
} H5E_END_TRY;
if (ret>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
size = H5Tget_ebias(type);
} H5E_END_TRY;
if (size>0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
inpad=H5Tget_inpad(type);
} H5E_END_TRY;
if (inpad>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
sign=H5Tget_sign(type);
} H5E_END_TRY;
if (sign>-1) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
tag = H5Tget_tag(type);
} H5E_END_TRY;
if (tag) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
H5E_BEGIN_TRY {
super = H5Tget_super(type);
} H5E_END_TRY;
if (super>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
+ FAIL_PUTS_ERROR("Operation not allowed for this type.");
} /* end if */
PASSED();
ret_value = 0;
- error:
- if (buf) HDfree(buf);
+error:
+ if(buf)
+ HDfree(buf);
+ if(tag)
+ HDfree(tag);
reset_hdf5();
- return ret_value;
+ return ret_value; /* Number of errors */
}