Code improvement

Description:
    Fixed potential division by zero occurrences and changed an assert to
    if statement.
Platforms tested:
    Linux/64 (jelly)
    Linux/64 (platypus)
    Darwin (osx1011test)
This commit is contained in:
Binh-Minh Ribler 2019-05-05 00:41:19 -05:00
parent 3bc708078c
commit bdf882ae39
3 changed files with 17 additions and 5 deletions

View File

@ -2396,9 +2396,13 @@ H5A__attr_post_copy_file(const H5O_loc_t *src_oloc, const H5A_t *attr_src,
/* Check for expanding references */
if(cpy_info->expand_ref) {
size_t ref_count;
size_t dst_dt_size; /* Destination datatype size */
/* Determine size of the destination datatype */
if(0 == (dst_dt_size = H5T_get_size(attr_dst->shared->dt)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to determine datatype size")
/* Determine # of reference elements to copy */
ref_count = attr_dst->shared->data_size / H5T_get_size(attr_dst->shared->dt);
ref_count = attr_dst->shared->data_size / dst_dt_size;
/* Copy objects referenced in source buffer to destination file and set destination elements */
if(H5O_copy_expand_ref(file_src, attr_dst->shared->data, file_dst, attr_dst->shared->data, ref_count, H5T_get_ref_type(attr_dst->shared->dt), cpy_info) < 0)

View File

@ -705,15 +705,18 @@ H5D__chunk_set_info_real(H5O_layout_chunk_t *layout, unsigned ndims,
/* Compute the # of chunks in dataset dimensions */
for(u = 0, layout->nchunks = 1, layout->max_nchunks = 1; u < ndims; u++) {
/* Sanity check */
HDassert(layout->dim[u] > 0);
/* Round up to the next integer # of chunks, to accommodate partial chunks */
layout->chunks[u] = ((curr_dims[u] + layout->dim[u]) - 1) / layout->dim[u];
if(H5S_UNLIMITED == max_dims[u])
layout->max_chunks[u] = H5S_UNLIMITED;
else
{
/* Sanity check */
if(layout->dim[u] == 0)
HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "dimension size must be > 0, dim = %u ", u)
layout->max_chunks[u] = ((max_dims[u] + layout->dim[u]) - 1) / layout->dim[u];
}
/* Accumulate the # of chunks */
layout->nchunks *= layout->chunks[u];

View File

@ -559,9 +559,14 @@ H5D__compact_copy(H5F_t *f_src, H5O_storage_compact_t *_storage_src, H5F_t *f_ds
/* Check for expanding references */
if(cpy_info->expand_ref) {
size_t ref_count;
size_t src_dt_size; /* Source datatype size */
/* Determine largest datatype size */
if(0 == (src_dt_size = H5T_get_size(dt_src)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to determine datatype size")
/* Determine # of reference elements to copy */
ref_count = storage_src->size / H5T_get_size(dt_src);
ref_count = storage_src->size / src_dt_size;
/* Copy objects referenced in source buffer to destination file and set destination elements */
if(H5O_copy_expand_ref(f_src, storage_src->buf, f_dst,