diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-03-06 21:19:57 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-03-06 21:19:57 (GMT) |
commit | a976ea9f7774ad2f8b23ff5dc4a3b46469a383fb (patch) | |
tree | 57021efe62c5ab852460eb710cca62c20d0885de /test/tvlstr.c | |
parent | fc5fde7a686b3018abc07eb7136cf9b9181b0eb9 (diff) | |
download | hdf5-a976ea9f7774ad2f8b23ff5dc4a3b46469a383fb.zip hdf5-a976ea9f7774ad2f8b23ff5dc4a3b46469a383fb.tar.gz hdf5-a976ea9f7774ad2f8b23ff5dc4a3b46469a383fb.tar.bz2 |
[svn-r18388] Description:
Bring changes from Coverity session from branch into trunk:
r18378:
Fixed coverity issues 207 and 322. Pointer hdr was checked for NULL after being
asserted and dereferenced. Check was removed.
r18379:
Fix coverity issues # 88 and # 435.
r18380:
Fixed Coverity issue # 85. Added check of returned pointer for NULL before use.
r18381:
Resolve coverity issues # 214 and # 215
r18382:
Issue 131: Add null checks to allocations and check for free in error handling
r18383:
Issue 421:
Reorganized code to make intention clearer. Also, set local variable fl to NULL
after transfer to tail. Heap->freelist will take care of all allocations
r18384:
Coverity #249 and #250 - STRING_ATT_CHECK wasn't allocated before being used
and freed in function test_write_vl_string_attribute and
test_read_vl_string_attribute.
Tested on:
Mac OS X/32 10.6.2 (amazon) w/debug & prod
(h5committested in daily tests)
Diffstat (limited to 'test/tvlstr.c')
-rw-r--r-- | test/tvlstr.c | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/test/tvlstr.c b/test/tvlstr.c index a411b86..fbced5f 100644 --- a/test/tvlstr.c +++ b/test/tvlstr.c @@ -573,7 +573,7 @@ static void test_write_vl_string_attribute(void) hid_t file, root, dataspace, att; hid_t type; herr_t ret; - char *string_att_check; + char *string_att_check = NULL; /* Open the file */ file = H5Fopen(DATAFILE, H5F_ACC_RDWR, H5P_DEFAULT); @@ -599,13 +599,21 @@ static void test_write_vl_string_attribute(void) ret = H5Awrite(att, type, &string_att); CHECK(ret, FAIL, "H5Awrite"); - ret = H5Aread(att, type, &string_att_check); - CHECK(ret, FAIL, "H5Aread"); + /* Allocate memory for read buffer */ + if(string_att) + string_att_check = (char*)HDmalloc((strlen(string_att) + 1) * sizeof(char)); + CHECK(string_att_check, NULL, "HDmalloc"); - if(HDstrcmp(string_att_check,string_att)!=0) - TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + if(string_att_check) { + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); - HDfree(string_att_check); + if(HDstrcmp(string_att_check,string_att)!=0) + TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + + HDfree(string_att_check); + string_att_check = NULL; + } ret = H5Aclose(att); CHECK(ret, FAIL, "HAclose"); @@ -620,13 +628,23 @@ static void test_write_vl_string_attribute(void) ret = H5Awrite(att, type, &string_att_write); CHECK(ret, FAIL, "H5Awrite"); - ret = H5Aread(att, type, &string_att_check); - CHECK(ret, FAIL, "H5Aread"); + /* Allocate memory for read buffer */ + if(string_att_write) + string_att_check = (char*)HDmalloc((strlen(string_att_write) + 1) * sizeof(char)); + CHECK(string_att_check, NULL, "HDmalloc"); + + if(string_att_check) { + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); - if(HDstrcmp(string_att_check,string_att_write)!=0) - TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); + if(HDstrcmp(string_att_check,string_att_write)!=0) + TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); + + /* The attribute string written is freed below, in the + *test_read_vl_string_attribute() test */ + HDfree(string_att_check); + } - HDfree(string_att_check); /* The attribute string written is freed below, in the test_read_vl_string_attribute() test */ /* HDfree(string_att_write); */ @@ -659,7 +677,7 @@ static void test_read_vl_string_attribute(void) hid_t file, root, att; hid_t type; herr_t ret; - char *string_att_check; + char *string_att_check = NULL; /* Open file */ file = H5Fopen(DATAFILE, H5F_ACC_RDONLY, H5P_DEFAULT); @@ -679,13 +697,21 @@ static void test_read_vl_string_attribute(void) att = H5Aopen(root, "test_scalar", H5P_DEFAULT); CHECK(att, FAIL, "H5Aopen"); - ret = H5Aread(att, type, &string_att_check); - CHECK(ret, FAIL, "H5Aread"); + /* Allocate memory for read buffer */ + if(string_att) + string_att_check = (char*)HDmalloc((strlen(string_att) + 1) * sizeof(char)); + CHECK(string_att_check, NULL, "HDmalloc"); - if(HDstrcmp(string_att_check,string_att)!=0) - TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + if(string_att_check) { + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); - HDfree(string_att_check); + if(HDstrcmp(string_att_check,string_att)!=0) + TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + + HDfree(string_att_check); + string_att_check = NULL; + } ret = H5Aclose(att); CHECK(ret, FAIL, "HAclose"); @@ -694,14 +720,24 @@ static void test_read_vl_string_attribute(void) att = H5Aopen(root, "test_scalar_large", H5P_DEFAULT); CHECK(att, FAIL, "H5Aopen"); - ret = H5Aread(att, type, &string_att_check); - CHECK(ret, FAIL, "H5Aread"); + /* Allocate memory for read buffer */ + if(string_att_write) + string_att_check = (char*)HDmalloc((strlen(string_att_write) + 1) * sizeof(char)); + CHECK(string_att_check, NULL, "HDmalloc"); + + if(string_att_check) { + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); - if(HDstrcmp(string_att_check,string_att_write)!=0) - TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); + if(HDstrcmp(string_att_check,string_att_write)!=0) + TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); + + HDfree(string_att_check); + } - HDfree(string_att_check); - HDfree(string_att_write); /* Free string allocated in test_write_vl_string_attribute */ + /* Free string allocated in test_write_vl_string_attribute */ + if(string_att_write) + HDfree(string_att_write); ret = H5Aclose(att); CHECK(ret, FAIL, "HAclose"); |