summaryrefslogtreecommitdiffstats
path: root/test/tattr.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-20 02:23:44 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-20 02:23:44 (GMT)
commit0c39a78927ae1e4b7471f96743a8cf5dd30350b0 (patch)
tree21eb68c066d6ef8a139278439d02c89202ce970f /test/tattr.c
parent7bac0bb48dd18809fa015e91848dc8756c0fe536 (diff)
downloadhdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.zip
hdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.tar.gz
hdf5-0c39a78927ae1e4b7471f96743a8cf5dd30350b0.tar.bz2
[svn-r18300] Description:
Bring Coverity fixes from branch to trunk: r18282: Fix Coverity issue #428 by wrapping testing calls with if(pass) {} block. r18283: Fix Coverity issue #425 by wrapping test calls in if(pass) {} block r18284: Issue 166: init_error() malloc'd 3 pointers in initialization and never freed inc ase of errors. Init pointers to NULL, check allocation results and free allocations in error block r18285: Fix Coverity issue #410 by wrapping test calls with if(pass) {} block. r18286: Issue 165: custom_print_cb() needed allocations freed in error block. r18287: Fix coverity issue # 409 Added if (pass) checks around calls to flush_cache. Additionally, added a check for file_ptr = NULL after call to setup_cache. r18288: Fix coverity# 107 free fh in H5HF_close() correctly before exit the function even when failure occurs. r18289: Fix Coverity issue #429: correct failure return values to match return type from routine. r18290: Fix Coverity issue #103: release allocated indirect section on error r18294: Issue 153, 152: Check allocations and free allocations in error block. Also cleaned up hid_t identifer that were opened in error block. r18295: Fix coverity# 101 free new_loc in H5HF_man_iter_start_entry() correctly before exit the function even when failure occurs r18296: Fix coverity# 100 free down_loc in H5HF_man_iter_down() before exit the function when failure occurs r18297: Fixed coverity issues 54, 55 and 216. Correctly handle the various ways that allocation of attr_name can fail in test_attr_basic_write. r18298: Fix coverity# 119 free object in H5HG_read() before exit the function when failure occurs r18299: Fix coverity issue #112: Add cleanup during error handling of H5MP_create. Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production Misc. Linux configurations (on original checkins)
Diffstat (limited to 'test/tattr.c')
-rw-r--r--test/tattr.c68
1 files changed, 38 insertions, 30 deletions
diff --git a/test/tattr.c b/test/tattr.c
index 484d83f..828b8a8 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -274,60 +274,68 @@ test_attr_basic_write(hid_t fapl)
attr_name_size = H5Aget_name(attr, (size_t)0, NULL);
CHECK(attr_name_size, FAIL, "H5Aget_name");
- if(attr_name_size > 0)
+ if(attr_name_size > 0) {
attr_name = (char*)HDcalloc((size_t)(attr_name_size + 1), sizeof(char));
-
- ret = (herr_t)H5Aget_name(attr, (size_t)(attr_name_size + 1), attr_name);
- CHECK(ret, FAIL, "H5Aget_name");
- ret = HDstrcmp(attr_name, ATTR_TMP_NAME);
- VERIFY(ret, 0, "HDstrcmp");
-
- if(attr_name)
- HDfree(attr_name);
+ CHECK(attr_name, NULL, "HDcalloc");
+
+ if(attr_name) {
+ ret = (herr_t)H5Aget_name(attr, (size_t)(attr_name_size + 1), attr_name);
+ CHECK(ret, FAIL, "H5Aget_name");
+ ret = HDstrcmp(attr_name, ATTR_TMP_NAME);
+ VERIFY(ret, 0, "HDstrcmp");
+
+ HDfree(attr_name);
+ attr_name = NULL;
+ } /* end if */
+ } /* end if */
/* Read attribute information immediately, without closing attribute */
ret = H5Aread(attr, H5T_NATIVE_INT, read_data1);
CHECK(ret, FAIL, "H5Aread");
/* Verify values read in */
- for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1[i]!=read_data1[i])
- TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]);
+ for(i = 0; i < ATTR1_DIM1; i++)
+ if(attr_data1[i] != read_data1[i])
+ TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1[i], i, read_data1[i]);
/* Close attribute */
- ret=H5Aclose(attr);
+ ret = H5Aclose(attr);
CHECK(ret, FAIL, "H5Aclose");
/* Open the second attribute again */
- attr2=H5Aopen(dataset, ATTR1A_NAME, H5P_DEFAULT);
+ attr2 = H5Aopen(dataset, ATTR1A_NAME, H5P_DEFAULT);
CHECK(attr, FAIL, "H5Aopen");
/* Verify new attribute name */
attr_name_size = H5Aget_name(attr2, (size_t)0, NULL);
CHECK(attr_name_size, FAIL, "H5Aget_name");
- if(attr_name_size>0)
+ if(attr_name_size > 0) {
attr_name = (char*)HDcalloc((size_t)(attr_name_size+1), sizeof(char));
-
- ret=(herr_t)H5Aget_name(attr2, (size_t)(attr_name_size+1), attr_name);
- CHECK(ret, FAIL, "H5Aget_name");
- ret=HDstrcmp(attr_name, ATTR1A_NAME);
- VERIFY(ret, 0, "HDstrcmp");
-
- if(attr_name)
- HDfree(attr_name);
+ CHECK(attr_name, NULL, "HDcalloc");
+
+ if(attr_name) {
+ ret = (herr_t)H5Aget_name(attr2, (size_t)(attr_name_size + 1), attr_name);
+ CHECK(ret, FAIL, "H5Aget_name");
+ ret = HDstrcmp(attr_name, ATTR1A_NAME);
+ VERIFY(ret, 0, "HDstrcmp");
+
+ HDfree(attr_name);
+ attr_name = NULL;
+ } /* end if */
+ } /* end if */
/* Read attribute information immediately, without closing attribute */
- ret=H5Aread(attr2,H5T_NATIVE_INT,read_data1);
+ ret = H5Aread(attr2, H5T_NATIVE_INT, read_data1);
CHECK(ret, FAIL, "H5Aread");
/* Verify values read in */
- for(i=0; i<ATTR1_DIM1; i++)
- if(attr_data1a[i]!=read_data1[i])
- TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1a[i],i,read_data1[i]);
+ for(i = 0; i < ATTR1_DIM1; i++)
+ if(attr_data1a[i] != read_data1[i])
+ TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d, read_data1[%d]=%d\n", __LINE__, i, attr_data1a[i], i, read_data1[i]);
/* Close attribute */
- ret=H5Aclose(attr2);
+ ret = H5Aclose(attr2);
CHECK(ret, FAIL, "H5Aclose");
ret = H5Sclose(sid1);
@@ -1539,7 +1547,7 @@ test_attr_delete(hid_t fapl)
CHECK(attr, FAIL, "H5Aopen_by_idx");
/* Verify Name */
- name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN,attr_name);
+ name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR1_NAME), "H5Aget_name");
if(HDstrcmp(attr_name, ATTR1_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR1_NAME);
@@ -1555,7 +1563,7 @@ test_attr_delete(hid_t fapl)
/* Verify Name */
name_len = H5Aget_name(attr, (size_t)ATTR_NAME_LEN, attr_name);
VERIFY(name_len, HDstrlen(ATTR3_NAME), "H5Aget_name");
- if(HDstrcmp(attr_name,ATTR3_NAME))
+ if(HDstrcmp(attr_name, ATTR3_NAME))
TestErrPrintf("attribute name different: attr_name=%s, should be %s\n",attr_name,ATTR3_NAME);
/* Close attribute */