summaryrefslogtreecommitdiffstats
path: root/test/dsets.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-03 19:41:48 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-03 19:41:48 (GMT)
commit77a3cc2292f6021a306372284c20882b8dc8eeeb (patch)
tree16353ba544c939c32750fef938aee693f3fd05ad /test/dsets.c
parent05bdd6d7293128b774eef1590c016c447e6e14ed (diff)
downloadhdf5-77a3cc2292f6021a306372284c20882b8dc8eeeb.zip
hdf5-77a3cc2292f6021a306372284c20882b8dc8eeeb.tar.gz
hdf5-77a3cc2292f6021a306372284c20882b8dc8eeeb.tar.bz2
[svn-r17954] Description:
Bring r17953 from trunk to 1.8 branch: Bring Coverity changes into the trunk: r17877: Error 266: Uninitialized memspace set to -1. Changed malloc and free to HDmalloc and HDfree. Removed unused dtype var. r17878: Error 265: Uninitialized mem_space set to -1. Changed malloc and free to HDmalloc and HDfree. Error 267: Uninitialized smspace set to -1. Changed malloc and free to HDmalloc and HDfree. r17879: Error 242: Uninitialized aid set to -1. Error 243: Uninitialized sid set to -1. Uninitialized tid set to -1 for consistency r17880: Error 242: reinitialized aid to -1 after close to be ready for reuse. Error 243: reinitialized sid to -1 after close to be ready for reuse. reinitialized tid to -1 for consistency after close to be ready for reuse. r17881: use valgrind to check there is a memory leak. The fix is to free ptrstr in line 5838 at xml_dump_group() of h5dump.c after it is used. run the valgrind after the fix, no memory leak for that part of the code. r17882: Fix Coverity items 256 and 269. r17883: Error 222-230: initialized hid_t vars to -1 after close to be ready for reuse. Also added H5Tclose for tid in gent_bigdims r17884: Bug fix (Coverity run2, view 23, dead code) (this is pair-program done by Albert, Elena and Larry). Confirmed and fixed the deadcode in hyperslab read branch of function diff_datasetid. (Discovered other bad code that diff_datasetid() should be recoded. Bug 1693 is entered for this.) r17906: Fix Coverity item 260. r17907: 262: Initialized hid_t's dtype, dtype_tmp and file to -1. Initialized H5T_t * dt to NULL. r17908: Fix Coverity item 261. r17909: Fix Coverity item 248. r17910: Revise fix for Coverity item 248. r17911: Resolved coverity issues #s 263, 162, 163, 164. All issues in dsets.c. Initialized fid and did hid_t's. filter_corrupt function was returning in the middle of an if statement, bypassing free calls. Updated error handling to free buffers and hid_t's appropriately. r17912: (done by Larry and Albert) Cleanup Coverity view warnings (#231-241) about using uninitialized variables. Initialized all of them. r17913: Resolved issue 251 and 264. Initialized tid2 to -1 and initialized buffers that were freed in case of an error. r17914: Resolved coverity issues 66, 220, and 221: 66: Negative Return assignment ignored 220,221: Initialized hid_t's. r17915: Fix Coverity item 247. r17916: Fix Coverity item 246. r17917: Fix Coverity item 245. r17918: Fix Coverity item 244. r17919: Coverity Issue #84: Moved asserts in H5T_cmp to the top of the function, and converted them to HDassert. Coverity complaining about using potentially NULL pointer without checking it. Want to see if Coverity will accept Assertions as acceptable checking before using the value. Tested on: FreeBSD/32 6.3 (duty) w/debug (h5committested on trunk)
Diffstat (limited to 'test/dsets.c')
-rw-r--r--test/dsets.c94
1 files changed, 63 insertions, 31 deletions
diff --git a/test/dsets.c b/test/dsets.c
index cea9325..9f4b06d 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -715,7 +715,9 @@ test_max_compact(hid_t fapl)
compact_size = (SIXTY_FOUR_KB-64)/sizeof(int);
wbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size);
+ assert(wbuf);
rbuf = (int*)HDmalloc(sizeof(int)*(size_t)compact_size);
+ assert(rbuf);
n=0;
for(i=0; i<(int)compact_size; i++)
@@ -772,8 +774,9 @@ test_max_compact(hid_t fapl)
if(H5Dclose(dataset) < 0) goto error;
if(H5Fclose(file) < 0) goto error;
HDfree(wbuf);
+ wbuf = NULL;
HDfree(rbuf);
-
+ rbuf = NULL;
/* Test compact dataset of size 64KB */
@@ -807,6 +810,19 @@ test_max_compact(hid_t fapl)
return 0;
error:
+ if(wbuf)
+ HDfree(wbuf);
+ if(rbuf)
+ HDfree(rbuf);
+
+ H5E_BEGIN_TRY {
+ /* Close file */
+ H5Sclose(space);
+ H5Pclose(plist);
+ H5Fclose(file);
+ H5Dclose(dataset);
+ } H5E_END_TRY;
+
return -1;
}
@@ -978,10 +994,10 @@ error:
static herr_t
test_tconv(hid_t file)
{
- char *out=NULL, *in=NULL;
- int i;
+ char *out = NULL, *in = NULL;
hsize_t dims[1];
- hid_t space, dataset;
+ hid_t space = -1, dataset = -1;
+ int i;
out = (char *)HDmalloc((size_t)(4 * 1000 * 1000));
HDassert(out);
@@ -992,11 +1008,11 @@ test_tconv(hid_t file)
/* Initialize the dataset */
for(i = 0; i < 1000000; i++) {
- out[i*4+0] = 0x11;
- out[i*4+1] = 0x22;
- out[i*4+2] = 0x33;
- out[i*4+3] = 0x44;
- }
+ out[i * 4 + 0] = 0x11;
+ out[i * 4 + 1] = 0x22;
+ out[i * 4 + 2] = 0x33;
+ out[i * 4 + 3] = 0x44;
+ } /* end for */
/* Create the data space */
dims[0] = 1000000;
@@ -1013,27 +1029,39 @@ test_tconv(hid_t file)
/* Read data with byte order conversion */
if(H5Dread(dataset, H5T_STD_I32BE, H5S_ALL, H5S_ALL, H5P_DEFAULT, in) < 0)
- goto error;
+ goto error;
/* Check */
for(i = 0; i < 1000000; i++) {
- if(in[4*i+0]!=out[4*i+3] ||
- in[4*i+1]!=out[4*i+2] ||
- in[4*i+2]!=out[4*i+1] ||
- in[4*i+3]!=out[4*i+0]) {
- H5_FAILED();
- puts(" Read with byte order conversion failed.");
- goto error;
- }
+ if(in[4 * i + 0] != out[4 * i + 3] ||
+ in[4 * i + 1] != out[4 * i + 2] ||
+ in[4 * i + 2] != out[4 * i + 1] ||
+ in[4 * i + 3] != out[4 * i + 0]) {
+ H5_FAILED();
+ puts(" Read with byte order conversion failed.");
+ goto error;
+ }
}
if(H5Dclose(dataset) < 0) goto error;
- free (out);
- free (in);
+ if(H5Sclose(space) < 0) goto error;
+ HDfree(out);
+ HDfree(in);
+
puts(" PASSED");
return 0;
- error:
+error:
+ if(out)
+ HDfree(out);
+ if(in)
+ HDfree(in);
+
+ H5E_BEGIN_TRY {
+ H5Dclose(dataset);
+ H5Sclose(space);
+ } H5E_END_TRY;
+
return -1;
}
@@ -1246,19 +1274,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts,
const unsigned int *cd_values, size_t nbytes,
size_t *buf_size, void **buf)
{
- size_t ret_value = 0;
+ void *data;
unsigned char *dst = (unsigned char*)(*buf);
unsigned int offset;
unsigned int length;
unsigned int value;
- void *data;
+ size_t ret_value = 0;
- if(cd_nelmts!=3 || !cd_values)
+ if(cd_nelmts != 3 || !cd_values)
return 0;
offset = cd_values[0];
length = cd_values[1];
value = cd_values[2];
- if(offset>nbytes || (offset+length)>nbytes || length<sizeof(unsigned int))
+ if(offset > nbytes || (offset + length) > nbytes || length < sizeof(unsigned int))
return 0;
data = HDmalloc((size_t)length);
@@ -1266,15 +1294,19 @@ filter_corrupt(unsigned int flags, size_t cd_nelmts,
if(flags & H5Z_FLAG_REVERSE) { /* Varify data is actually corrupted during read */
dst += offset;
- if(HDmemcmp(data, dst, (size_t)length)!=0) return 0;
- *buf_size = nbytes;
- ret_value = nbytes;
- } else { /* Write corrupted data */
+ if(HDmemcmp(data, dst, (size_t)length) != 0)
+ ret_value = 0;
+ else {
+ *buf_size = nbytes;
+ ret_value = nbytes;
+ } /* end else */
+ } /* end if */
+ else { /* Write corrupted data */
dst += offset;
HDmemcpy(dst, data, (size_t)length);
*buf_size = nbytes;
- ret_value = *buf_size;
- }
+ ret_value = *buf_size;
+ } /* end else */
if(data)
HDfree(data);