summaryrefslogtreecommitdiffstats
path: root/test/dsets.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2010-02-27 20:08:03 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2010-02-27 20:08:03 (GMT)
commitd3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0 (patch)
tree31816c1a7204c609ae6e7ea3e8b99ce518eaad87 /test/dsets.c
parentc90711e71362716cd9ab25d6b9167ca49edccfe8 (diff)
downloadhdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.zip
hdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.tar.gz
hdf5-d3a9b81fd06423cb81c8f4fa49f2e4c265a9c3d0.tar.bz2
[svn-r18346] Description:
Bring Coverity fixes back from branch to trunk: r18336: Fix coverity issues 275, 276, 277, 323, 432, 433, and 434 r18337: Fix Coverity issue #106: release free space section node on error r18338: Fixed Coverity #94 - In H5P_register, new_class wasn't closed when there's an error after it's created. r18339: Fix Coverity #185 - In test_conv_str_1, BUF wasn't freed when there's an error in this function. r18340: Correct error in r18337 that wasn't releasing indirect fractal heap block early enough. r18341: Close nodes if any failed in the middle of allocating new nodes. Coverity 140 and 141 r18342: Correct [another] problem w/r18337. r18343: Fix coverity items 185, 20, and 21. r18344: Fix Coverity 213 - In H5FD_family_close, the double pointer file->memb was dereferenced without NULL checking (We believe). r18345: Fix Coverity issue # 210; removed NULL check after pointer dereferenced in H5HFdblock.c. Also assigned NULL to pointer in H5Pint.c to fix segmentation fault. Tested on: FreeBSD/32 6.3 (duty) in debug mode FreeBSD/64 6.3 (liberty) w/C++ & FORTRAN, in debug mode Linux/32 2.6 (jam) w/PGI compilers, w/default API=1.8.x, w/C++ & FORTRAN, w/threadsafe, in debug mode Linux/64-amd64 2.6 (amani) w/Intel compilers, w/default API=1.6.x, w/C++ & FORTRAN, in production mode Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN, w/szip filter, in production mode Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN, in production mode Linux/64-ia64 2.4 (tg-login3) w/parallel, w/FORTRAN, in debug mode Linux/64-amd64 2.6 (abe) w/parallel, w/FORTRAN, in production mode Mac OS X/32 10.6.2 (amazon) in debug mode Mac OS X/32 10.6.2 (amazon) w/C++ & FORTRAN, w/threadsafe, in production mode
Diffstat (limited to 'test/dsets.c')
-rw-r--r--test/dsets.c122
1 files changed, 66 insertions, 56 deletions
diff --git a/test/dsets.c b/test/dsets.c
index 9c70875..4865ba9 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -685,93 +685,100 @@ test_compact_io(hid_t fapl)
* Purpose: Tests compact dataset of maximal size.
*
* Return: Success: 0
- *
* Failure: -1
*
* Programmer: Raymond Lu
* August 8, 2002
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
test_max_compact(hid_t fapl)
{
- hid_t file, dataset, space, plist;
+ hid_t file = -1;
+ hid_t dataset = -1;
+ hid_t space = -1;
+ hid_t plist = -1;
hsize_t dims[1];
- hsize_t compact_size;
- herr_t status;
- int *wbuf, *rbuf;
+ size_t compact_size;
+ int *wbuf = NULL;
+ int *rbuf = NULL;
char filename[FILENAME_BUF_SIZE];
- int i, n;
+ int n;
+ size_t u;
TESTING("compact dataset of maximal size");
/* Test compact dataset of size 64KB-64 */
/* Initialize data */
- compact_size = (SIXTY_FOUR_KB-64)/sizeof(int);
+ 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);
+ if(NULL == (wbuf = (int *)HDmalloc(sizeof(int) * compact_size)))
+ TEST_ERROR
+ if(NULL == (rbuf = (int *)HDmalloc(sizeof(int) * compact_size)))
+ TEST_ERROR
- n=0;
- for(i=0; i<(int)compact_size; i++)
- wbuf[i] = n++;
+ n = 0;
+ for(u = 0; u < compact_size; u++)
+ wbuf[u] = n++;
/* Create a small data space for compact dataset */
- dims[0] = compact_size;
- space = H5Screate_simple(1, dims, NULL);
- assert(space>=0);
+ dims[0] = (hsize_t)compact_size;
+ if((space = H5Screate_simple(1, dims, NULL)) < 0)
+ FAIL_STACK_ERROR
/* Create a file */
h5_fixname(FILENAME[3], fapl, filename, sizeof filename);
- if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
- goto error;
+ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
+ FAIL_STACK_ERROR
/* Create property list for compact dataset creation */
- plist = H5Pcreate(H5P_DATASET_CREATE);
- assert(plist >= 0);
- status = H5Pset_layout(plist, H5D_COMPACT);
- assert(status >= 0);
+ if((plist = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ FAIL_STACK_ERROR
+ if(H5Pset_layout(plist, H5D_COMPACT) < 0)
+ FAIL_STACK_ERROR
/* Create and write to a compact dataset */
if((dataset = H5Dcreate2(file, DSET_COMPACT_MAX_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT, plist, H5P_DEFAULT)) < 0)
- goto error;
+ FAIL_STACK_ERROR
if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0)
- goto error;
+ FAIL_STACK_ERROR
/* Close file */
- if(H5Sclose(space) < 0) goto error;
- if(H5Pclose(plist) < 0) goto error;
- if(H5Dclose(dataset) < 0) goto error;
- if(H5Fclose(file) < 0) goto error;
+ if(H5Sclose(space) < 0)
+ FAIL_STACK_ERROR
+ if(H5Pclose(plist) < 0)
+ FAIL_STACK_ERROR
+ if(H5Dclose(dataset) < 0)
+ FAIL_STACK_ERROR
+ if(H5Fclose(file) < 0)
+ FAIL_STACK_ERROR
/*
* Open the file and check data
*/
if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
- goto error;
+ FAIL_STACK_ERROR
if((dataset = H5Dopen2(file, DSET_COMPACT_MAX_NAME, H5P_DEFAULT)) < 0)
- goto error;
+ FAIL_STACK_ERROR
if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0)
- goto error;
+ FAIL_STACK_ERROR
/* Check that the values read are the same as the values written */
- for(i = 0; i < (int)compact_size; i++)
- if(rbuf[i] != wbuf[i]) {
+ for(u = 0; u < compact_size; u++)
+ if(rbuf[u] != wbuf[u]) {
H5_FAILED();
printf(" Read different values than written.\n");
- printf(" At index %d\n", i);
+ printf(" At index %u\n", (unsigned)u);
goto error;
} /* end if */
- if(H5Dclose(dataset) < 0) goto error;
- if(H5Fclose(file) < 0) goto error;
+ if(H5Dclose(dataset) < 0)
+ FAIL_STACK_ERROR
+ if(H5Fclose(file) < 0)
+ FAIL_STACK_ERROR
HDfree(wbuf);
wbuf = NULL;
HDfree(rbuf);
@@ -780,20 +787,20 @@ test_max_compact(hid_t fapl)
/* Test compact dataset of size 64KB */
/* Create a data space for compact dataset */
- compact_size = SIXTY_FOUR_KB/sizeof(int);
- dims[0] = compact_size;
- space = H5Screate_simple(1, dims, NULL);
- assert(space>=0);
+ compact_size = SIXTY_FOUR_KB / sizeof(int);
+ dims[0] = (hsize_t)compact_size;
+ if((space = H5Screate_simple(1, dims, NULL)) < 0)
+ FAIL_STACK_ERROR
/* Open file */
- if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
+ if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
goto error;
/* Create property list for compact dataset creation */
- plist = H5Pcreate(H5P_DATASET_CREATE);
- assert(plist >= 0);
- status = H5Pset_layout(plist, H5D_COMPACT);
- assert(status >= 0);
+ if((plist = H5Pcreate(H5P_DATASET_CREATE)) < 0)
+ FAIL_STACK_ERROR
+ if(H5Pset_layout(plist, H5D_COMPACT) < 0)
+ FAIL_STACK_ERROR
/* Create and write to a compact dataset */
H5E_BEGIN_TRY {
@@ -801,9 +808,12 @@ test_max_compact(hid_t fapl)
} H5E_END_TRY;
/* Close file */
- H5Sclose(space);
- H5Pclose(plist);
- H5Fclose(file);
+ if(H5Sclose(space) < 0)
+ FAIL_STACK_ERROR
+ if(H5Pclose(plist) < 0)
+ FAIL_STACK_ERROR
+ if(H5Fclose(file) < 0)
+ FAIL_STACK_ERROR
PASSED();
return 0;
@@ -823,7 +833,7 @@ error:
} H5E_END_TRY;
return -1;
-}
+} /* end test_max_compact() */
/*-------------------------------------------------------------------------
@@ -998,10 +1008,10 @@ test_tconv(hid_t file)
hid_t space = -1, dataset = -1;
int i;
- out = (char *)HDmalloc((size_t)(4 * 1000 * 1000));
- HDassert(out);
- in = (char *)HDmalloc((size_t)(4 * 1000 * 1000));
- HDassert(in);
+ if ((out = (char *)HDmalloc((size_t)(4 * 1000 * 1000))) == NULL)
+ goto error;
+ if ((in = (char *)HDmalloc((size_t)(4 * 1000 * 1000))) == NULL)
+ goto error;
TESTING("data type conversion");