diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:00:00 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-01-23 07:00:00 (GMT) |
commit | bb25c85e794449d3bf59d8811e53288569161790 (patch) | |
tree | e6c37cf6f8bba9323540ddddb70300b43351d88f /test | |
parent | fcc03a356b4dd5e58cc88b692b3d05d75b8ae5d0 (diff) | |
download | hdf5-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')
-rw-r--r-- | test/cache.c | 122 | ||||
-rw-r--r-- | test/dt_arith.c | 2 | ||||
-rw-r--r-- | test/dtypes.c | 148 |
3 files changed, 132 insertions, 140 deletions
diff --git a/test/cache.c b/test/cache.c index 734fc3b..7828725 100644 --- a/test/cache.c +++ b/test/cache.c @@ -13769,45 +13769,53 @@ check_expunge_entry(void) * it without marking it dirty. */ - protect_entry(cache_ptr, 0, 0); + if ( pass ) { - unprotect_entry(cache_ptr, 0, 0, FALSE, H5C__NO_FLAGS_SET); + protect_entry(cache_ptr, 0, 0); + + unprotect_entry(cache_ptr, 0, 0, FALSE, H5C__NO_FLAGS_SET); + + } if ( pass ) { result = H5C_get_entry_status(cache_ptr, entry_ptr->addr, &entry_size, &in_cache, &is_dirty, &is_protected, &is_pinned, NULL, NULL); - if ( result < 0 ) { + if ( result < 0 ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, - "H5AC_get_entry_status() reports failure 2."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, + "H5AC_get_entry_status() reports failure 2."); + failure_mssg = msg; - } else if ( !in_cache || is_dirty || is_protected || is_pinned ) { + } else if ( !in_cache || is_dirty || is_protected || is_pinned ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, "Unexpected status 2."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, "Unexpected status 2."); + failure_mssg = msg; - } else if ( ( ! entry_ptr->loaded ) || - ( entry_ptr->cleared ) || - ( entry_ptr->flushed ) || - ( entry_ptr->destroyed ) ) { + } else if ( ( ! entry_ptr->loaded ) || + ( entry_ptr->cleared ) || + ( entry_ptr->flushed ) || + ( entry_ptr->destroyed ) ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, "Unexpected entry history 2."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, "Unexpected entry history 2."); + failure_mssg = msg; - } + } } /* Expunge the entry and then verify that it is no longer in the cache. * Also verify that the entry was loaded, cleared, and destroyed, but * not flushed. */ - expunge_entry(cache_ptr, 0, 0); + if ( pass ) { + + expunge_entry(cache_ptr, 0, 0); + + } if ( pass ) { @@ -13818,29 +13826,29 @@ check_expunge_entry(void) result = H5C_get_entry_status(cache_ptr, entry_ptr->addr, &entry_size, &in_cache, &is_dirty, &is_protected, &is_pinned, NULL, NULL); - if ( result < 0 ) { + if ( result < 0 ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, - "H5AC_get_entry_status() reports failure 3."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, + "H5AC_get_entry_status() reports failure 3."); + failure_mssg = msg; - } else if ( in_cache ) { + } else if ( in_cache ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, "Unexpected status 3."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, "Unexpected status 3."); + failure_mssg = msg; - } else if ( ( ! entry_ptr->loaded ) || - ( ! entry_ptr->cleared ) || - ( entry_ptr->flushed ) || - ( ! entry_ptr->destroyed ) ) { + } else if ( ( ! entry_ptr->loaded ) || + ( ! entry_ptr->cleared ) || + ( entry_ptr->flushed ) || + ( ! entry_ptr->destroyed ) ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, "Unexpected entry history 3."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, "Unexpected entry history 3."); + failure_mssg = msg; - } + } } /* now repeat the process with a different entry. On unprotect @@ -13860,14 +13868,14 @@ check_expunge_entry(void) &in_cache, &is_dirty, &is_protected, &is_pinned, NULL, NULL); - if ( result < 0 ) { + if ( result < 0 ) { - pass = FALSE; - HDsnprintf(msg, (size_t)128, - "H5AC_get_entry_status() reports failure 4."); - failure_mssg = msg; + pass = FALSE; + HDsnprintf(msg, (size_t)128, + "H5AC_get_entry_status() reports failure 4."); + failure_mssg = msg; - } else if ( in_cache ) { + } else if ( in_cache ) { pass = FALSE; HDsnprintf(msg, (size_t)128, "Unexpected status 4."); @@ -13882,16 +13890,20 @@ check_expunge_entry(void) HDsnprintf(msg, (size_t)128, "Unexpected entry history 4."); failure_mssg = msg; - } + } } /* protect the entry to force the cache to load it, and then unprotect * it with the dirty flag set. */ - protect_entry(cache_ptr, 0, 1); + if ( pass ) { + + protect_entry(cache_ptr, 0, 1); + + unprotect_entry(cache_ptr, 0, 1, TRUE, H5C__NO_FLAGS_SET); - unprotect_entry(cache_ptr, 0, 1, TRUE, H5C__NO_FLAGS_SET); + } if ( pass ) { @@ -13899,14 +13911,14 @@ check_expunge_entry(void) &in_cache, &is_dirty, &is_protected, &is_pinned, NULL, NULL); - if ( result < 0 ) { + if ( result < 0 ) { pass = FALSE; HDsnprintf(msg, (size_t)128, "H5AC_get_entry_status() reports failure 5."); failure_mssg = msg; - } else if ( !in_cache || !is_dirty || is_protected || is_pinned ) { + } else if ( !in_cache || !is_dirty || is_protected || is_pinned ) { pass = FALSE; HDsnprintf(msg, (size_t)128, "Unexpected status 5."); @@ -13921,14 +13933,18 @@ check_expunge_entry(void) HDsnprintf(msg, (size_t)128, "Unexpected entry history 5."); failure_mssg = msg; - } + } } /* Expunge the entry and then verify that it is no longer in the cache. * Also verify that the entry was loaded, cleared and destroyed, but not * flushed. */ - expunge_entry(cache_ptr, 0, 1); + if ( pass ) { + + expunge_entry(cache_ptr, 0, 1); + + } if ( pass ) { @@ -13940,14 +13956,14 @@ check_expunge_entry(void) &in_cache, &is_dirty, &is_protected, &is_pinned, NULL, NULL); - if ( result < 0 ) { + if ( result < 0 ) { pass = FALSE; HDsnprintf(msg, (size_t)128, "H5AC_get_entry_status() reports failure 6."); failure_mssg = msg; - } else if ( in_cache ) { + } else if ( in_cache ) { pass = FALSE; HDsnprintf(msg, (size_t)128, "Unexpected status 6."); @@ -13962,7 +13978,7 @@ check_expunge_entry(void) HDsnprintf(msg, (size_t)128, "Unexpected entry history 6."); failure_mssg = msg; - } + } } if ( pass ) { diff --git a/test/dt_arith.c b/test/dt_arith.c index 13cf5ba..ff6b4e0 100644 --- a/test/dt_arith.c +++ b/test/dt_arith.c @@ -1334,7 +1334,6 @@ test_derived_integer(void) char filename[1024]; size_t src_size, dst_size; unsigned char *buf=NULL, *saved_buf=NULL; - int *aligned=NULL; int endian; /*endianess */ size_t nelmts = NTESTELEM; unsigned int fails_this_test = 0; @@ -1597,7 +1596,6 @@ test_derived_integer(void) error: if (buf) free(buf); if (saved_buf) free(saved_buf); - if (aligned) free(aligned); HDfflush(stdout); H5E_BEGIN_TRY { H5Tclose (tid1); 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 */ } |