diff options
author | jhendersonHDF <jhenderson@hdfgroup.org> | 2021-06-16 20:45:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 20:45:26 (GMT) |
commit | bb7dfbebdcaf3a838d03167a309b9934b997ce92 (patch) | |
tree | abd9e0690ace1a47cc8c6a7e73c49281d38483c3 /hl/test | |
parent | e4e9bb70db3ee275977caad4b494021af41619d7 (diff) | |
download | hdf5-bb7dfbebdcaf3a838d03167a309b9934b997ce92.zip hdf5-bb7dfbebdcaf3a838d03167a309b9934b997ce92.tar.gz hdf5-bb7dfbebdcaf3a838d03167a309b9934b997ce92.tar.bz2 |
Fix several warnings (#747)
Diffstat (limited to 'hl/test')
-rw-r--r-- | hl/test/test_ds.c | 33 | ||||
-rw-r--r-- | hl/test/test_file_image.c | 30 |
2 files changed, 42 insertions, 21 deletions
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index ead5c65..786aba8 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -406,10 +406,10 @@ create_int_dataset(hid_t fid, const char *dsidx, int fulldims) herr_t create_long_dataset(hid_t fid, const char *dsname, const char *dsidx, int fulldims) { - int rank = 4; - int rankds = 1; - hsize_t dims[4] = {DIM1_SIZE, DIM2_SIZE, DIM3_SIZE, DIM4_SIZE}; - long * buf; + int rank = 4; + int rankds = 1; + hsize_t dims[4] = {DIM1_SIZE, DIM2_SIZE, DIM3_SIZE, DIM4_SIZE}; + long * buf = NULL; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; hsize_t s3_dim[1] = {DIM3_SIZE}; @@ -431,49 +431,54 @@ create_long_dataset(hid_t fid, const char *dsname, const char *dsidx, int fulldi /* Allocate buffer */ if (NULL == (buf = (long *)HDmalloc(sizeof(long) * DIM1_SIZE * DIM2_SIZE * DIM3_SIZE * DIM4_SIZE))) - return FAIL; + goto error; /* make a dataset */ if (H5LTmake_dataset_long(fid, dsname, rank, dims, buf) >= 0) { if (fulldims == 0) { /* make a DS dataset for the first dimension */ if (create_DS1_long_datasets(fid, dsidx, rankds, s1_dim, s1_wbuf, NULL) < 0) - return FAIL; + goto error; /* make a DS dataset for the second dimension */ if (create_DS2_long_datasets(fid, dsidx, rankds, s2_dim, s2_wbuf, NULL, NULL) < 0) - return FAIL; + goto error; /* make a DS dataset for the third dimension */ if (create_DS3_long_datasets(fid, dsidx, rankds, s3_dim, s3_wbuf, NULL, NULL, NULL) < 0) - return FAIL; + goto error; /* make a DS dataset for the fourth dimension */ if (create_DS4_long_datasets(fid, dsidx, rankds, s4_dim, s4_wbuf, NULL, NULL, NULL, NULL) < 0) - return FAIL; + goto error; } else { if (create_DS1_long_datasets(fid, dsidx, rankds, s1_dim, s1_wbuf, s11_wbuf) < 0) - return FAIL; + goto error; if (create_DS2_long_datasets(fid, dsidx, rankds, s2_dim, s2_wbuf, s21_wbuf, s22_wbuf) < 0) - return FAIL; + goto error; if (create_DS3_long_datasets(fid, dsidx, rankds, s3_dim, s3_wbuf, s31_wbuf, s32_wbuf, s33_wbuf) < 0) - return FAIL; + goto error; if (create_DS4_long_datasets(fid, dsidx, rankds, s4_dim, s4_wbuf, s41_wbuf, s42_wbuf, s43_wbuf, s44_wbuf) < 0) - return FAIL; + goto error; } } else - return FAIL; + goto error; HDfree(buf); return SUCCEED; + +error: + HDfree(buf); + + return FAIL; } herr_t diff --git a/hl/test/test_file_image.c b/hl/test/test_file_image.c index b397a81..bde8adc 100644 --- a/hl/test/test_file_image.c +++ b/hl/test/test_file_image.c @@ -53,8 +53,8 @@ static int test_file_image(size_t open_images, size_t nflags, const unsigned *flags) { - hid_t * file_id, *dset_id, file_space, plist; /* HDF5 ids */ - hsize_t dims1[RANK] = {2, 3}; /* original dimension of datasets */ + hid_t * file_id = NULL, *dset_id = NULL, file_space, plist; /* HDF5 ids */ + hsize_t dims1[RANK] = {2, 3}; /* original dimension of datasets */ hsize_t max_dims[RANK] = {H5S_UNLIMITED, H5S_UNLIMITED}; int data1[6] = {1, 2, 3, 4, 5, 6}; /* original contents of dataset */ int data2[6] = {7, 8, 9, 10, 11, 12}; /* "wrong" contents of dataset */ @@ -63,10 +63,10 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags) hsize_t dims4[RANK] = {3, 5}; /* extended dimensions of datasets */ int data4[15] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; /* extended contents of dataset */ - ssize_t * buf_size; /* pointer to array of buffer sizes */ - void ** buf_ptr; /* pointer to array of pointers to image buffers */ - char ** filename; /* pointer to array of pointers to filenames */ - unsigned * input_flags; /* pointer to array of flag combinations */ + ssize_t * buf_size = NULL; /* pointer to array of buffer sizes */ + void ** buf_ptr = NULL; /* pointer to array of pointers to image buffers */ + char ** filename = NULL; /* pointer to array of pointers to filenames */ + unsigned * input_flags = NULL; /* pointer to array of flag combinations */ size_t i, j, k, nrow, n_values; herr_t status1; void * handle_ptr = NULL; /* pointers to driver buffer */ @@ -85,7 +85,7 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags) FAIL_PUTS_ERROR("malloc() failed"); /* allocate array to store the name of each of the open images */ - if (NULL == (filename = (char **)HDmalloc(sizeof(char *) * open_images))) + if (NULL == (filename = (char **)HDcalloc(1, sizeof(char *) * open_images))) FAIL_PUTS_ERROR("malloc() failed"); /* allocate array to store the size of each of the open images */ @@ -110,6 +110,8 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags) /* allocate name buffer for image i */ filename[i] = (char *)HDmalloc(sizeof(char) * 32); + if (!filename[i]) + FAIL_PUTS_ERROR("HDmalloc() failed"); /* create file name */ HDsprintf(filename[i], "image_file%d.h5", (int)i); @@ -232,6 +234,9 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags) if (input_flags[i] & H5LT_FILE_IMAGE_OPEN_RW && !(input_flags[i] & H5LT_FILE_IMAGE_DONT_COPY)) { void *tmp_ptr = HDmalloc((size_t)buf_size[i]); + if (!tmp_ptr) + FAIL_PUTS_ERROR("buffer allocation failed"); + /* Copy vfd buffer to a temporary buffer */ HDmemcpy(tmp_ptr, (void *)*core_buf_ptr_ptr, (size_t)buf_size[i]); /* Clear status_flags in the superblock for the vfd buffer: file locking is using status_flags @@ -525,6 +530,17 @@ test_file_image(size_t open_images, size_t nflags, const unsigned *flags) return 0; error: + if (filename) { + for (i = 0; i < open_images; i++) + HDfree(filename[i]); + HDfree(filename); + } + HDfree(file_id); + HDfree(dset_id); + HDfree(buf_ptr); + HDfree(buf_size); + HDfree(input_flags); + H5_FAILED(); return -1; } |