Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several warnings #2 #747

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions hl/src/H5LT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2146,19 +2146,28 @@ realloc_and_append(hbool_t _no_user_buf, size_t *len, char *buf, const char *str
size_t size_str_to_add, size_str;

if (_no_user_buf) {
char *tmp_realloc;

if (!buf)
goto out;

/* If the buffer isn't big enough, reallocate it. Otherwise, go to do strcat. */
if (str_to_add && ((ssize_t)(*len - (HDstrlen(buf) + HDstrlen(str_to_add) + 1)) < LIMIT)) {
*len += ((HDstrlen(buf) + HDstrlen(str_to_add) + 1) / INCREMENT + 1) * INCREMENT;
buf = (char *)HDrealloc(buf, *len);
}
else if (!str_to_add && ((ssize_t)(*len - HDstrlen(buf) - 1) < LIMIT)) {
*len += INCREMENT;
buf = (char *)HDrealloc(buf, *len);
}
}

if (!buf)
goto out;
tmp_realloc = (char *)HDrealloc(buf, *len);
if (tmp_realloc == NULL) {
HDfree(buf);
buf = NULL;
goto out;
}
else
buf = tmp_realloc;
}

if (str_to_add) {
/* find the size of the buffer to add */
Expand Down Expand Up @@ -2374,9 +2383,9 @@ print_enum(hid_t type, char *str, size_t *str_len, hbool_t no_ubuf, size_t indt)
herr_t
H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *len)
{
size_t str_len = INCREMENT;
char * text_str;
herr_t ret = SUCCEED;
size_t str_len = INCREMENT;
char * text_str = NULL;
herr_t ret = SUCCEED;

if (lang_type <= H5LT_LANG_ERR || lang_type >= H5LT_NO_LANG)
goto out;
Expand All @@ -2400,6 +2409,8 @@ H5LTdtype_to_text(hid_t dtype, char *str, H5LT_lang_t lang_type, size_t *len)
return ret;

out:
HDfree(text_str);

return FAIL;
}

Expand Down Expand Up @@ -2779,10 +2790,14 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, hb
if (H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
goto out;
stmp = (char *)HDcalloc(super_len, sizeof(char));
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) {
HDfree(stmp);
goto out;
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp)))
}
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp))) {
HDfree(stmp);
goto out;
}

if (stmp)
HDfree(stmp);
Expand Down Expand Up @@ -2822,10 +2837,14 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, hb
if (H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
goto out;
stmp = (char *)HDcalloc(super_len, sizeof(char));
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) {
HDfree(stmp);
goto out;
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp)))
}
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp))) {
HDfree(stmp);
goto out;
}

if (stmp)
HDfree(stmp);
Expand Down Expand Up @@ -2879,10 +2898,14 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, hb
if (H5LTdtype_to_text(super, NULL, lang, &super_len) < 0)
goto out;
stmp = (char *)HDcalloc(super_len, sizeof(char));
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0)
if (H5LTdtype_to_text(super, stmp, lang, &super_len) < 0) {
HDfree(stmp);
goto out;
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp)))
}
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, stmp))) {
HDfree(stmp);
goto out;
}
if (stmp)
HDfree(stmp);
stmp = NULL;
Expand Down Expand Up @@ -2933,10 +2956,14 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, hb
if (H5LTdtype_to_text(mtype, NULL, lang, &mlen) < 0)
goto out;
mtmp = (char *)HDcalloc(mlen, sizeof(char));
if (H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0)
if (H5LTdtype_to_text(mtype, mtmp, lang, &mlen) < 0) {
HDfree(mtmp);
goto out;
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, mtmp)))
}
if (!(dt_str = realloc_and_append(no_user_buf, slen, dt_str, mtmp))) {
HDfree(mtmp);
goto out;
}
if (mtmp)
HDfree(mtmp);
mtmp = NULL;
Expand Down
33 changes: 19 additions & 14 deletions hl/test/test_ds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand Down
30 changes: 23 additions & 7 deletions hl/test/test_file_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 3 additions & 6 deletions src/H5.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,9 @@ H5check_version(unsigned majnum, unsigned minnum, unsigned relnum)
* Check only the first sizeof(lib_str) char. Assume the information
* will fit within this size or enough significance.
*/
HDsnprintf(lib_str, sizeof(lib_str), "HDF5 library version: %d.%d.%d", H5_VERS_MAJOR, H5_VERS_MINOR,
H5_VERS_RELEASE);
if (*substr) {
HDstrncat(lib_str, "-", (size_t)1);
HDstrncat(lib_str, substr, (sizeof(lib_str) - HDstrlen(lib_str)) - 1);
} /* end if */
HDsnprintf(lib_str, sizeof(lib_str), "HDF5 library version: %d.%d.%d%s%s", H5_VERS_MAJOR,
H5_VERS_MINOR, H5_VERS_RELEASE, (*substr ? "-" : ""), substr);

if (HDstrcmp(lib_str, H5_lib_vers_info_g) != 0) {
HDfputs("Warning! Library version information error.\n"
"The HDF5 library version information are not "
Expand Down
24 changes: 18 additions & 6 deletions src/H5CX.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,15 +1768,19 @@ H5CX_get_ring(void)
hbool_t
H5CX_get_coll_metadata_read(void)
{
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
hbool_t coll_md_read = FALSE;

FUNC_ENTER_NOAPI_NOINIT_NOERR

/* Sanity check */
head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */
HDassert(head && *head);

FUNC_LEAVE_NOAPI((*head)->ctx.coll_metadata_read)
/* Set return value */
coll_md_read = (*head)->ctx.coll_metadata_read;

FUNC_LEAVE_NOAPI(coll_md_read)
} /* end H5CX_get_coll_metadata_read() */

/*-------------------------------------------------------------------------
Expand Down Expand Up @@ -1830,15 +1834,19 @@ H5CX_get_mpi_coll_datatypes(MPI_Datatype *btype, MPI_Datatype *ftype)
hbool_t
H5CX_get_mpi_file_flushing(void)
{
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
hbool_t flushing = FALSE;

FUNC_ENTER_NOAPI_NOINIT_NOERR

/* Sanity check */
head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */
HDassert(head && *head);

FUNC_LEAVE_NOAPI((*head)->ctx.mpi_file_flushing)
/* Set return value */
flushing = (*head)->ctx.mpi_file_flushing;

FUNC_LEAVE_NOAPI(flushing)
} /* end H5CX_get_mpi_file_flushing() */

/*-------------------------------------------------------------------------
Expand All @@ -1857,15 +1865,19 @@ H5CX_get_mpi_file_flushing(void)
hbool_t
H5CX_get_mpio_rank0_bcast(void)
{
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
H5CX_node_t **head = NULL; /* Pointer to head of API context list */
hbool_t do_rank0_bcast = FALSE;

FUNC_ENTER_NOAPI_NOINIT_NOERR

/* Sanity check */
head = H5CX_get_my_context(); /* Get the pointer to the head of the API context, for this thread */
HDassert(head && *head);

FUNC_LEAVE_NOAPI((*head)->ctx.rank0_bcast)
/* Set return value */
do_rank0_bcast = (*head)->ctx.rank0_bcast;

FUNC_LEAVE_NOAPI(do_rank0_bcast)
} /* end H5CX_get_mpio_rank0_bcast() */
#endif /* H5_HAVE_PARALLEL */

Expand Down
5 changes: 2 additions & 3 deletions src/H5Dchunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4989,7 +4989,7 @@ H5D__chunk_collective_fill(const H5D_t *dset, H5D_chunk_coll_info_t *chunk_info,
* order of offset in the file.
*/
if (need_addr_sort)
HDqsort(chunk_disp_array, blocks, sizeof(MPI_Aint), H5D__chunk_cmp_addr);
HDqsort(chunk_disp_array, (size_t)blocks, sizeof(MPI_Aint), H5D__chunk_cmp_addr);

/* MSC - should use this if MPI_type_create_hindexed block is working:
* mpi_code = MPI_Type_create_hindexed_block(blocks, block_len, chunk_disp_array, MPI_BYTE,
Expand Down Expand Up @@ -7478,14 +7478,13 @@ H5D__chunk_iter_cb(const H5D_chunk_rec_t *chunk_rec, void *udata)
const H5D_chunk_iter_ud_t *data = (H5D_chunk_iter_ud_t *)udata;
int ret_value = H5_ITER_CONT;

FUNC_ENTER_STATIC
FUNC_ENTER_STATIC_NOERR

/* Check for callback failure and pass along return value */
if ((ret_value = (data->op)(chunk_rec->scaled, chunk_rec->filter_mask, chunk_rec->chunk_addr,
chunk_rec->nbytes, data->op_data)) < 0)
HERROR(H5E_DATASET, H5E_CANTNEXT, "iteration operator failed");

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D__chunk_iter_cb */

Expand Down
2 changes: 2 additions & 0 deletions src/H5FDhdfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
* File System (HDFS).
*/

#ifdef H5_HAVE_LIBHDFS
/* This source code file is part of the H5FD driver module */
#include "H5FDdrvr_module.h"
#endif

#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
Expand Down
Loading