diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-08-20 21:37:12 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-08-20 21:37:12 (GMT) |
commit | 47c3bc7540869f53f0b734c68d3289835f0a546d (patch) | |
tree | 90e688dc21b095d9d3d36e944465ac79eff05348 /src | |
parent | b2012d9f74843ec87b31b7aca0c3ad8b6b6fe448 (diff) | |
download | hdf5-47c3bc7540869f53f0b734c68d3289835f0a546d.zip hdf5-47c3bc7540869f53f0b734c68d3289835f0a546d.tar.gz hdf5-47c3bc7540869f53f0b734c68d3289835f0a546d.tar.bz2 |
[svn-r19272] Description:
Close out various resource leaks and usages of uninitialized memory that
were flagged by valgrind. [There's still some more valgrind warnings, but
it's better now... :-/ ]
Also clean up warnings and code formatting.
Tested on:
Mac OS X/32 10.6.4 (amazon) w/debug & valgrind
(h5committest forthcoming)
Diffstat (limited to 'src')
-rw-r--r-- | src/H5A.c | 7 | ||||
-rw-r--r-- | src/H5Aint.c | 10 | ||||
-rw-r--r-- | src/H5Dfill.c | 12 | ||||
-rw-r--r-- | src/H5F.c | 14 | ||||
-rw-r--r-- | src/H5FDsec2.c | 7 | ||||
-rw-r--r-- | src/H5Faccum.c | 3 | ||||
-rw-r--r-- | src/H5Gent.c | 4 | ||||
-rw-r--r-- | src/H5HFtiny.c | 3 | ||||
-rw-r--r-- | src/H5Ocopy.c | 10 | ||||
-rw-r--r-- | src/H5Odtype.c | 2 | ||||
-rw-r--r-- | src/H5Olayout.c | 11 | ||||
-rwxr-xr-x | src/H5SM.c | 2 | ||||
-rw-r--r-- | src/H5SMcache.c | 5 | ||||
-rw-r--r-- | src/H5SMmessage.c | 4 | ||||
-rw-r--r-- | src/H5Tvlen.c | 171 | ||||
-rw-r--r-- | src/H5Zdeflate.c | 25 | ||||
-rw-r--r-- | src/H5Zscaleoffset.c | 13 |
17 files changed, 139 insertions, 164 deletions
@@ -2424,18 +2424,19 @@ H5A_close(H5A_t *attr) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release object header info") /* Reference count can be 0. It only happens when H5A_create fails. */ - if(1 >= attr->shared->nrefs) { + if(attr->shared->nrefs <= 1) { /* Free dynamicly allocated items */ if(H5A_free(attr) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTRELEASE, FAIL, "can't release attribute info") /* Destroy shared attribute struct */ attr->shared = H5FL_FREE(H5A_shared_t, attr->shared); - } else if(attr->shared->nrefs > 1) { + } /* end if */ + else { /* There are other references to the shared part of the attribute. * Only decrement the reference count. */ --attr->shared->nrefs; - } + } /* end else */ /* Free group hierarchy path */ if(H5G_name_free(&(attr->path)) < 0) diff --git a/src/H5Aint.c b/src/H5Aint.c index ba30506..101d604 100644 --- a/src/H5Aint.c +++ b/src/H5Aint.c @@ -1149,8 +1149,8 @@ H5A_dense_copy_file_cb(const H5A_t *attr_src, void *_udata) HDassert(udata->file); HDassert(udata->cpy_info); - if ( NULL == (attr_dst=H5A_attr_copy_file(attr_src, udata->file, - udata->recompute_size, udata->cpy_info, udata->dxpl_id))) + if(NULL == (attr_dst = H5A_attr_copy_file(attr_src, udata->file, + udata->recompute_size, udata->cpy_info, udata->dxpl_id))) HGOTO_ERROR(H5E_ATTR, H5E_CANTCOPY, H5_ITER_ERROR, "can't copy attribute") /* Reset shared location information */ @@ -1168,10 +1168,8 @@ H5A_dense_copy_file_cb(const H5A_t *attr_src, void *_udata) H5_END_TAG(H5_ITER_ERROR); done: - if(attr_dst) { - (void)H5A_free(attr_dst); - attr_dst = H5FL_FREE(H5A_t, attr_dst); - } /* end if */ + if(attr_dst && H5A_close(attr_dst) < 0) + HDONE_ERROR(H5E_ATTR, H5E_CLOSEERROR, FAIL, "can't close destination attribute") FUNC_LEAVE_NOAPI(ret_value) } /* end H5A_dense_copy_file_cb() */ diff --git a/src/H5Dfill.c b/src/H5Dfill.c index 467ce4b..f6e07f2 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -585,7 +585,7 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed") /* Replicate the fill value into the cached buffer */ - H5V_array_fill(fb_info->fill_buf, fb_info->fill_buf, fb_info->mem_elmt_size, nelmts); + H5V_array_fill((void *)((unsigned char *)fb_info->fill_buf + fb_info->mem_elmt_size), fb_info->fill_buf, fb_info->mem_elmt_size, nelmts); /* Reset the entire background buffer, if necessary */ if(H5T_path_bkg(fb_info->mem_to_dset_tpath)) @@ -606,12 +606,14 @@ H5D_fill_refill_vl(H5D_fill_buf_info_t *fb_info, size_t nelmts, hid_t dxpl_id) HGOTO_ERROR(H5E_DATASET, H5E_CANTCONVERT, FAIL, "data type conversion failed") done: - if (buf) { + if(buf) { /* Free dynamically allocated VL elements in fill buffer */ - if (fb_info->fill->type) - H5T_vlen_reclaim_elmt(buf, fb_info->fill->type, dxpl_id); + if(fb_info->fill->type) + if(H5T_vlen_reclaim_elmt(buf, fb_info->fill->type, dxpl_id) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't reclaim vlen element") else - H5T_vlen_reclaim_elmt(buf, fb_info->mem_type, dxpl_id); + if(H5T_vlen_reclaim_elmt(buf, fb_info->mem_type, dxpl_id) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "can't reclaim vlen element") /* Free temporary fill buffer */ if(fb_info->fill_free_func) @@ -1197,12 +1197,18 @@ H5F_open(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, tent_flags = flags; if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) { - if(tent_flags == flags) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") + if(tent_flags == flags) { + time_t mytime = HDtime(NULL); + + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime), name, tent_flags) + } /* end if */ H5E_clear_stack(NULL); tent_flags = flags; - if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file") + if(NULL == (lf = H5FD_open(name, tent_flags, fapl_id, HADDR_UNDEF))) { + time_t mytime = HDtime(NULL); + + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', tent_flags = %x", HDctime(&mytime), name, tent_flags) + } /* end if */ } /* end if */ /* Is the file already open? */ diff --git a/src/H5FDsec2.c b/src/H5FDsec2.c index 7e54063..d9fa4d9 100644 --- a/src/H5FDsec2.c +++ b/src/H5FDsec2.c @@ -356,9 +356,8 @@ H5FD_sec2_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) /* Open the file */ if((fd = HDopen(name, o_flags, 0666)) < 0) { int myerrno = errno; - time_t mytime = HDtime(NULL); - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: time = %s, name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", HDctime(&mytime), name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); + HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file: name = '%s', errno = %d, error message = '%s', flags = %x, o_flags = %x", name, myerrno, HDstrerror(myerrno), flags, (unsigned)o_flags); } /* end if */ if(HDfstat(fd, &sb) < 0) HSYS_GOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file") @@ -822,9 +821,9 @@ H5FD_sec2_write(H5FD_t *_file, H5FD_mem_t UNUSED type, hid_t UNUSED dxpl_id, had if(!H5F_addr_defined(addr)) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "addr undefined, addr = %llu", (unsigned long long)addr) if(REGION_OVERFLOW(addr, size)) - HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) + HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu", (unsigned long long)addr, (unsigned long long)size) if((addr + size) > file->eoa) - HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu", (unsigned long long)addr) + HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, FAIL, "addr overflow, addr = %llu, size = %llu, eoa = %llu", (unsigned long long)addr, (unsigned long long)size, (unsigned long long)file->eoa) /* Seek to the correct location */ if((addr != file->pos || OP_WRITE != file->op) && diff --git a/src/H5Faccum.c b/src/H5Faccum.c index c170671..975a6e8 100644 --- a/src/H5Faccum.c +++ b/src/H5Faccum.c @@ -648,6 +648,9 @@ HDmemset(f->shared->accum.buf + clear_size, 0, (f->shared->accum.alloc_size - cl /* Note the new buffer size */ f->shared->accum.alloc_size = new_size; +#ifdef H5_CLEAR_MEMORY +HDmemset(f->shared->accum.buf + size, 0, (f->shared->accum.alloc_size - size)); +#endif /* H5_CLEAR_MEMORY */ } /* end if */ /* Update the metadata accumulator information */ diff --git a/src/H5Gent.c b/src/H5Gent.c index 69037d4..a2e6159 100644 --- a/src/H5Gent.c +++ b/src/H5Gent.c @@ -248,8 +248,8 @@ H5G_ent_encode(const H5F_t *f, uint8_t **pp, const H5G_entry_t *ent) } /* end else */ /* fill with zero */ - while(*pp < p_ret) - *(*pp)++ = 0; + if(*pp < p_ret) + HDmemset(*pp, 0, (p_ret - *pp)); *pp = p_ret; done: diff --git a/src/H5HFtiny.c b/src/H5HFtiny.c index ce91bd1..f11b6c0 100644 --- a/src/H5HFtiny.c +++ b/src/H5HFtiny.c @@ -178,6 +178,9 @@ HDfprintf(stderr, "%s: obj_size = %Zu\n", FUNC, obj_size); *id++ = enc_obj_size & H5HF_TINY_MASK_EXT_2; } /* end else */ HDmemcpy(id, obj, obj_size); +#ifdef H5_CLEAR_MEMORY +HDmemset(id + obj_size, 0, (hdr->id_len - (1 + hdr->tiny_len_extended + obj_size))); +#endif /* H5_CLEAR_MEMORY */ /* Update statistics about heap */ hdr->tiny_size += obj_size; diff --git a/src/H5Ocopy.c b/src/H5Ocopy.c index 8e55503..7a10765 100644 --- a/src/H5Ocopy.c +++ b/src/H5Ocopy.c @@ -575,7 +575,15 @@ H5O_copy_header_real(const H5O_loc_t *oloc_src, H5O_loc_t *oloc_dst /*out */, addr_new = oh_dst->chunk[0].addr; /* Create memory image for the new chunk */ - if(NULL == (oh_dst->chunk[0].image = H5FL_BLK_MALLOC(chunk_image, (size_t)dst_oh_size))) + /* Note: we use calloc() instead of malloc() here because older versions of + * some messages don't initialize "unused" bytes and because we want to + * write out the same version of the object header and older versions of + * object headers aligned messages. In both those situations, it's + * complex and error-prone to determine all the proper ways/places to + * clear to zero bytes, so we just set the buffer to zero's here. + * (QAK - 2010/08/17) + */ + if(NULL == (oh_dst->chunk[0].image = H5FL_BLK_CALLOC(chunk_image, (size_t)dst_oh_size))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") /* Set dest. chunk information */ diff --git a/src/H5Odtype.c b/src/H5Odtype.c index fec695e..51694a3 100644 --- a/src/H5Odtype.c +++ b/src/H5Odtype.c @@ -1272,7 +1272,7 @@ H5O_dtype_size(const H5F_t *f, const void *_mesg) /* (starting with version 3 of the datatype message, use the minimum # of bytes required) */ if(dt->shared->version >= H5O_DTYPE_VERSION_3) ret_value += offset_nbytes; /*member offset*/ - if(dt->shared->version >= H5O_DTYPE_VERSION_2) + else if(dt->shared->version == H5O_DTYPE_VERSION_2) ret_value += 4; /*member offset*/ else ret_value += 4 + /*member offset*/ diff --git a/src/H5Olayout.c b/src/H5Olayout.c index 67dbf4d..e413598 100644 --- a/src/H5Olayout.c +++ b/src/H5Olayout.c @@ -584,6 +584,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, H5D_copy_file_ud_t *udata = (H5D_copy_file_ud_t *)_udata; /* Dataset copying user data */ H5O_layout_t *layout_src = (H5O_layout_t *) mesg_src; H5O_layout_t *layout_dst = NULL; + hbool_t copied = FALSE; /* Whether the data was copied */ void *ret_value; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5O_layout_copy_file) @@ -607,6 +608,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* copy compact raw data */ if(H5D_compact_copy(file_src, &layout_src->storage.u.compact, file_dst, &layout_dst->storage.u.compact, udata->src_dtype, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") + copied = TRUE; } /* end if */ break; @@ -615,7 +617,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, * layout message less than version 3 because versions 1 & 2 would * truncate the dimension sizes to 32-bits of information. - QAK 5/26/04 */ - if(layout_src->version < 3) + if(layout_src->version < H5O_LAYOUT_VERSION_3) layout_dst->storage.u.contig.size = H5S_extent_nelem(udata->src_space_extent) * H5T_get_size(udata->src_dtype); @@ -623,6 +625,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* copy contiguous raw data */ if(H5D_contig_copy(file_src, &layout_src->storage.u.contig, file_dst, &layout_dst->storage.u.contig, udata->src_dtype, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy contiguous storage") + copied = TRUE; } /* end if */ break; @@ -631,6 +634,7 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, /* Create chunked layout */ if(H5D_chunk_copy(file_src, &layout_src->storage.u.chunk, &layout_src->u.chunk, file_dst, &layout_dst->storage.u.chunk, udata->src_space_extent, udata->src_dtype, udata->common.src_pline, cpy_info, dxpl_id) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, NULL, "unable to copy chunked storage") + copied = TRUE; } /* end if */ break; @@ -638,8 +642,9 @@ H5O_layout_copy_file(H5F_t *file_src, void *mesg_src, H5F_t *file_dst, HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "Invalid layout class") } /* end switch */ - /* Freed by copy routine */ - udata->src_dtype = NULL; + /* Check if copy routine was invoked (which frees the source datatype) */ + if(copied) + udata->src_dtype = NULL; /* Set return value */ ret_value = layout_dst; @@ -1742,7 +1742,7 @@ H5SM_delete_from_index(H5F_t *f, hid_t dxpl_id, H5O_t *open_oh, /* If this returns failure, it means that the message wasn't found. * If it succeeds, a copy of the modified message will be returned. */ - if(H5B2_modify(bt2, dxpl_id, &key, H5SM_decr_ref, &message) <0) + if(H5B2_modify(bt2, dxpl_id, &key, H5SM_decr_ref, &message) < 0) HGOTO_ERROR(H5E_SOHM, H5E_NOTFOUND, FAIL, "message not in index") /* Point to the message */ diff --git a/src/H5SMcache.c b/src/H5SMcache.c index 4a9338b..1511fd0 100644 --- a/src/H5SMcache.c +++ b/src/H5SMcache.c @@ -605,7 +605,7 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis if(H5SM_message_encode(p, &(list->messages[x]), &ctx) < 0) HGOTO_ERROR(H5E_SOHM, H5E_CANTFLUSH, FAIL, "unable to write shared message to disk") - p+=H5SM_SOHM_ENTRY_SIZE(f); + p += H5SM_SOHM_ENTRY_SIZE(f); ++mesgs_written; } /* end if */ } /* end for */ @@ -614,6 +614,9 @@ H5SM_list_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5SM_lis /* Compute checksum on buffer */ computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); UINT32ENCODE(p, computed_chksum); +#ifdef H5_CLEAR_MEMORY +HDmemset(p, 0, (list->header->list_size - (p - buf))); +#endif /* H5_CLEAR_MEMORY */ /* Write the list to disk */ HDassert((size_t)(p - buf) <= list->header->list_size); diff --git a/src/H5SMmessage.c b/src/H5SMmessage.c index 32ded03..0d41a09 100644 --- a/src/H5SMmessage.c +++ b/src/H5SMmessage.c @@ -309,7 +309,7 @@ H5SM_message_encode(uint8_t *raw, const void *_nrecord, void *_ctx) *raw++ = 0; /* reserved (possible flags byte) */ *raw++ = (uint8_t)message->msg_type_id; UINT16ENCODE(raw, message->u.mesg_loc.index); - H5F_addr_encode_len(ctx->sizeof_addr, &raw, message->u.mesg_loc.oh_addr); + H5F_addr_encode_len((size_t)ctx->sizeof_addr, &raw, message->u.mesg_loc.oh_addr); } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -350,7 +350,7 @@ H5SM_message_decode(const uint8_t *raw, void *_nrecord, void *_ctx) raw++; /* reserved */ message->msg_type_id = *raw++; UINT16DECODE(raw, message->u.mesg_loc.index); - H5F_addr_decode_len(ctx->sizeof_addr, &raw, &message->u.mesg_loc.oh_addr); + H5F_addr_decode_len((size_t)ctx->sizeof_addr, &raw, &message->u.mesg_loc.oh_addr); } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) diff --git a/src/H5Tvlen.c b/src/H5Tvlen.c index 95f4086..f1b1f00 100644 --- a/src/H5Tvlen.c +++ b/src/H5Tvlen.c @@ -100,8 +100,6 @@ H5T_init_vlen_interface(void) * Programmer: Quincey Koziol * Thursday, May 20, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ hid_t @@ -144,8 +142,6 @@ done: * Programmer: Quincey Koziol * Tuesday, November 20, 2001 * - * Modifications: - * *------------------------------------------------------------------------- */ H5T_t * @@ -315,11 +311,6 @@ done: * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static ssize_t @@ -357,11 +348,6 @@ H5T_vlen_seq_mem_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static void * @@ -399,11 +385,6 @@ H5T_vlen_seq_mem_getptr(void *_vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -442,11 +423,6 @@ H5T_vlen_seq_mem_isnull(const H5F_t UNUSED *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of an hvl_t that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -489,8 +465,6 @@ H5T_vlen_seq_mem_read(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void *bu * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -548,8 +522,6 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -584,11 +556,6 @@ H5T_vlen_seq_mem_setnull(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ static ssize_t @@ -624,12 +591,6 @@ H5T_vlen_str_mem_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * Added assertion on _vl. - * *------------------------------------------------------------------------- */ static void * @@ -665,11 +626,6 @@ H5T_vlen_str_mem_getptr(void *_vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -702,11 +658,6 @@ H5T_vlen_str_mem_isnull(const H5F_t UNUSED *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: Neil Fortner - * Friday, August 22, 2008 - * Changed function to be tolerant of a char * that is not aligned - * properly in _vl. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -748,8 +699,6 @@ H5T_vlen_str_mem_read(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void *bu * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -797,8 +746,6 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -826,8 +773,6 @@ H5T_vlen_str_mem_setnull(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, void *_vl, void * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ static ssize_t @@ -857,8 +802,6 @@ H5T_vlen_disk_getlen(const void *_vl) * Programmer: Quincey Koziol * Saturday, June 12, 2004 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -884,8 +827,6 @@ H5T_vlen_disk_getptr(void UNUSED *vl) * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static htri_t @@ -919,8 +860,6 @@ H5T_vlen_disk_isnull(const H5F_t *f, void *_vl) * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * *------------------------------------------------------------------------- */ /* ARGSUSED */ @@ -967,29 +906,24 @@ done: * Programmer: Quincey Koziol * Wednesday, June 2, 1999 * - * Modifications: - * - * Raymond Lu - * Thursday, June 26, 2002 - * Free heap objects storing old data. - * *------------------------------------------------------------------------- */ /* ARGSUSED */ static herr_t -H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED *vl_alloc_info, void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) +H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED *vl_alloc_info, + void *_vl, void *buf, void *_bg, size_t seq_len, size_t base_size) { - uint8_t *vl=(uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg=(uint8_t *)_bg; /*Pointer to the old data hvl_t */ + uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ + uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ H5HG_t hobjid; /* New VL sequence's heap ID */ size_t len; /* Size of new sequence on disk (in bytes) */ - herr_t ret_value=SUCCEED; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_disk_write) /* check parameters */ HDassert(vl); - HDassert(seq_len==0 || buf); + HDassert(seq_len == 0 || buf); HDassert(f); /* Free heap object for old data. */ @@ -1004,9 +938,9 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED INT32DECODE(bg, bg_hobjid.idx); /* Free heap object for old data */ - if(bg_hobjid.addr>0) { + if(bg_hobjid.addr > 0) { /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid)<0) + if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") } /* end if */ } /* end if */ @@ -1015,13 +949,13 @@ H5T_vlen_disk_write(H5F_t *f, hid_t dxpl_id, const H5T_vlen_alloc_info_t UNUSED UINT32ENCODE(vl, seq_len); /* Write the VL information to disk (allocates space also) */ - len=(seq_len*base_size); - if(H5HG_insert(f,dxpl_id,len,buf,&hobjid)<0) + len = (seq_len*base_size); + if(H5HG_insert(f, dxpl_id, len, buf, &hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to write VL information") /* Encode the heap information */ - H5F_addr_encode(f,&vl,hobjid.addr); - INT32ENCODE(vl,hobjid.idx); + H5F_addr_encode(f, &vl, hobjid.addr); + INT32ENCODE(vl, hobjid.idx); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1038,17 +972,15 @@ done: * Programmer: Quincey Koziol * Saturday, November 8, 2003 * - * Modifications: - * *------------------------------------------------------------------------- */ static herr_t H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) { - uint8_t *vl=(uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ - uint8_t *bg=(uint8_t *)_bg; /*Pointer to the old data hvl_t */ - uint32_t seq_len=0; /* Sequence length */ - herr_t ret_value=SUCCEED; /* Return value */ + uint8_t *vl = (uint8_t *)_vl; /*Pointer to the user's hvl_t information*/ + uint8_t *bg = (uint8_t *)_bg; /*Pointer to the old data hvl_t */ + uint32_t seq_len = 0; /* Sequence length */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_disk_setnull) @@ -1057,7 +989,7 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) HDassert(vl); /* Free heap object for old data. */ - if(bg!=NULL) { + if(bg != NULL) { H5HG_t bg_hobjid; /* "Background" VL info sequence's ID info */ /* Skip the length of the sequence and heap object ID from background data. */ @@ -1068,9 +1000,9 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) INT32DECODE(bg, bg_hobjid.idx); /* Free heap object for old data */ - if(bg_hobjid.addr>0) { + if(bg_hobjid.addr > 0) { /* Free heap object */ - if(H5HG_remove(f, dxpl_id, &bg_hobjid)<0) + if(H5HG_remove(f, dxpl_id, &bg_hobjid) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_WRITEERROR, FAIL, "Unable to remove heap object") } /* end if */ } /* end if */ @@ -1079,8 +1011,8 @@ H5T_vlen_disk_setnull(H5F_t *f, hid_t dxpl_id, void *_vl, void *_bg) UINT32ENCODE(vl, seq_len); /* Encode the "nil" heap pointer information */ - H5F_addr_encode(f,&vl,(haddr_t)0); - INT32ENCODE(vl,0); + H5F_addr_encode(f, &vl, (haddr_t)0); + INT32ENCODE(vl, 0); done: FUNC_LEAVE_NOAPI(ret_value) @@ -1111,8 +1043,8 @@ done: static herr_t H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, void *free_info) { - unsigned i; /* local index variable */ - herr_t ret_value = SUCCEED; + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT(H5T_vlen_reclaim_recurse) @@ -1127,9 +1059,9 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - for(i=0; i<dt->shared->u.array.nelem; i++) { - off=((uint8_t *)elem)+i*(dt->shared->parent->shared->size); - if(H5T_vlen_reclaim_recurse(off,dt->shared->parent,free_func,free_info)<0) + for(u = 0; u < dt->shared->u.array.nelem; u++) { + off = ((uint8_t *)elem) + u * (dt->shared->parent->shared->size); + if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free array element") } /* end for */ } /* end if */ @@ -1137,14 +1069,14 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_COMPOUND: /* Check each field and recurse on VL, compound, enum or array ones */ - for (i=0; i<dt->shared->u.compnd.nmembs; i++) { + for(u = 0; u < dt->shared->u.compnd.nmembs; u++) { /* Recurse if it's VL, compound, enum or array */ - if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[i].type->shared->type)) { + if(H5T_IS_COMPLEX(dt->shared->u.compnd.memb[u].type->shared->type)) { void *off; /* offset of field */ /* Calculate the offset member and recurse on it */ - off=((uint8_t *)elem)+dt->shared->u.compnd.memb[i].offset; - if(H5T_vlen_reclaim_recurse(off,dt->shared->u.compnd.memb[i].type,free_func,free_info)<0) + off = ((uint8_t *)elem) + dt->shared->u.compnd.memb[u].offset; + if(H5T_vlen_reclaim_recurse(off, dt->shared->u.compnd.memb[u].type, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free compound field") } /* end if */ } /* end for */ @@ -1152,8 +1084,8 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi case H5T_VLEN: /* Recurse on the VL information if it's VL, compound, enum or array, then free VL sequence */ - if(dt->shared->u.vlen.type==H5T_VLEN_SEQUENCE) { - hvl_t *vl=(hvl_t *)elem; /* Temp. ptr to the vl info */ + if(dt->shared->u.vlen.type == H5T_VLEN_SEQUENCE) { + hvl_t *vl = (hvl_t *)elem; /* Temp. ptr to the vl info */ /* Check if there is anything actually in this sequence */ if(vl->len!=0) { @@ -1162,24 +1094,24 @@ H5T_vlen_reclaim_recurse(void *elem, const H5T_t *dt, H5MM_free_t free_func, voi void *off; /* offset of field */ /* Calculate the offset of each array element and recurse on it */ - while(vl->len>0) { - off=((uint8_t *)vl->p)+(vl->len-1)*dt->shared->parent->shared->size; - if(H5T_vlen_reclaim_recurse(off,dt->shared->parent,free_func,free_info)<0) + while(vl->len > 0) { + off = ((uint8_t *)vl->p) + (vl->len - 1) * dt->shared->parent->shared->size; + if(H5T_vlen_reclaim_recurse(off, dt->shared->parent, free_func, free_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "Unable to free VL element") vl->len--; } /* end while */ } /* end if */ /* Free the VL sequence */ - if(free_func!=NULL) - (*free_func)(vl->p,free_info); + if(free_func != NULL) + (*free_func)(vl->p, free_info); else H5MM_xfree(vl->p); } /* end if */ - } else if(dt->shared->u.vlen.type==H5T_VLEN_STRING) { + } else if(dt->shared->u.vlen.type == H5T_VLEN_STRING) { /* Free the VL string */ - if(free_func!=NULL) - (*free_func)(*(char **)elem,free_info); + if(free_func != NULL) + (*free_func)(*(char **)elem, free_info); else H5MM_xfree(*(char **)elem); } else { @@ -1226,7 +1158,7 @@ H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned UNUSED ndim, const hsize_t { H5T_vlen_alloc_info_t *vl_alloc_info = (H5T_vlen_alloc_info_t *)op_data; /* VL allocation info from iterator */ H5T_t *dt; - herr_t ret_value; + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(H5T_vlen_reclaim, FAIL) @@ -1235,11 +1167,12 @@ H5T_vlen_reclaim(void *elem, hid_t type_id, unsigned UNUSED ndim, const hsize_t HDassert(H5I_DATATYPE == H5I_get_type(type_id)); /* Check args */ - if (NULL==(dt=H5I_object_verify(type_id,H5I_DATATYPE))) + if(NULL == (dt = H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") /* Pull the free function and free info pointer out of the op_data and call the recurse datatype free function */ - ret_value=H5T_vlen_reclaim_recurse(elem,dt,vl_alloc_info->free_func,vl_alloc_info->free_info); + if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) @@ -1289,13 +1222,13 @@ H5T_vlen_get_alloc_info(hid_t dxpl_id, H5T_vlen_alloc_info_t **vl_alloc_info) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset transfer property list") /* Get the allocation functions & information */ - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_NAME,&(*vl_alloc_info)->alloc_func)<0) + if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_NAME,&(*vl_alloc_info)->alloc_func) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_INFO_NAME,&(*vl_alloc_info)->alloc_info)<0) + if (H5P_get(plist,H5D_XFER_VLEN_ALLOC_INFO_NAME,&(*vl_alloc_info)->alloc_info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_NAME,&(*vl_alloc_info)->free_func)<0) + if (H5P_get(plist,H5D_XFER_VLEN_FREE_NAME,&(*vl_alloc_info)->free_func) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") - if (H5P_get(plist,H5D_XFER_VLEN_FREE_INFO_NAME,&(*vl_alloc_info)->free_info)<0) + if (H5P_get(plist,H5D_XFER_VLEN_FREE_INFO_NAME,&(*vl_alloc_info)->free_info) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "unable to get value") } /* end else */ @@ -1318,8 +1251,6 @@ done: * Programmer: Mike McGreevy * May 11, 2010 * - * Modifications: - * *------------------------------------------------------------------------- */ herr_t @@ -1335,12 +1266,14 @@ H5T_vlen_reclaim_elmt(void *elem, H5T_t *dt, hid_t dxpl_id) FUNC_ENTER_NOAPI(H5T_vlen_reclaim_elmt, FAIL) /* Get VL allocation info */ - if (H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0) + if(H5T_vlen_get_alloc_info(dxpl_id, &vl_alloc_info) < 0) HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, FAIL, "unable to retrieve VL allocation info") /* Recurse on buffer to free dynamic fields */ - ret_value = H5T_vlen_reclaim_recurse(elem,dt,vl_alloc_info->free_func,vl_alloc_info->free_info); + if(H5T_vlen_reclaim_recurse(elem, dt, vl_alloc_info->free_func, vl_alloc_info->free_info) < 0) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTFREE, FAIL, "can't reclaim vlen elements") done: FUNC_LEAVE_NOAPI(ret_value) } /* H5T_vlen_reclaim_elmt */ + diff --git a/src/H5Zdeflate.c b/src/H5Zdeflate.c index 63e7b9a..598aa97 100644 --- a/src/H5Zdeflate.c +++ b/src/H5Zdeflate.c @@ -101,9 +101,9 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, /* Set the uncompression parameters */ HDmemset(&z_strm, 0, sizeof(z_strm)); - z_strm.next_in = *buf; + z_strm.next_in = (Bytef *)*buf; H5_ASSIGN_OVERFLOW(z_strm.avail_in,nbytes,size_t,unsigned); - z_strm.next_out = outbuf; + z_strm.next_out = (Bytef *)outbuf; H5_ASSIGN_OVERFLOW(z_strm.avail_out,nalloc,size_t,unsigned); /* Initialize the uncompression routines */ @@ -155,7 +155,7 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, /* Finish uncompressing the stream */ (void)inflateEnd(&z_strm); - } + } /* end if */ else { /* * Output; compress but fail if the result would be larger than the @@ -172,19 +172,20 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, H5_ASSIGN_OVERFLOW(aggression,cd_values[0],unsigned,int); /* Allocate output (compressed) buffer */ - if (NULL==(z_dst=outbuf=H5MM_malloc(z_dst_nbytes))) + if(NULL == (outbuf = H5MM_malloc(z_dst_nbytes))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, 0, "unable to allocate deflate destination buffer") + z_dst = (Bytef *)outbuf; /* Perform compression from the source to the destination buffer */ - status = compress2 (z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); + status = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression); /* Check for various zlib errors */ - if (Z_BUF_ERROR==status) + if(Z_BUF_ERROR == status) HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "overflow") - else if (Z_MEM_ERROR==status) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error") - else if (Z_OK!=status) - HGOTO_ERROR (H5E_PLINE, H5E_CANTINIT, 0, "other deflate error") + else if(Z_MEM_ERROR == status) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "deflate memory error") + else if(Z_OK != status) + HGOTO_ERROR(H5E_PLINE, H5E_CANTINIT, 0, "other deflate error") /* Successfully uncompressed the buffer */ else { /* Free the input buffer */ @@ -195,8 +196,8 @@ H5Z_filter_deflate (unsigned flags, size_t cd_nelmts, outbuf = NULL; *buf_size = nbytes; ret_value = z_dst_nbytes; - } - } + } /* end else */ + } /* end else */ done: if(outbuf) diff --git a/src/H5Zscaleoffset.c b/src/H5Zscaleoffset.c index 4bfc8b1..eb3c6e6 100644 --- a/src/H5Zscaleoffset.c +++ b/src/H5Zscaleoffset.c @@ -806,6 +806,11 @@ H5Z_set_local_scaleoffset(hid_t dcpl_id, hid_t type_id, hid_t space_id) if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype") +#ifdef H5_CLEAR_MEMORY + /* Initialize the parameters to a known state */ + HDmemset(cd_values, 0, sizeof(cd_values)); +#endif /* H5_CLEAR_MEMORY */ + /* Get the filter's current parameters */ if(H5P_get_filter_by_id(dcpl_plist, H5Z_FILTER_SCALEOFFSET, &flags, &cd_nelmts, cd_values, (size_t)0, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLINE, H5E_CANTGET, FAIL, "can't get scaleoffset parameters") @@ -1182,6 +1187,14 @@ H5Z_filter_scaleoffset(unsigned flags, size_t cd_nelmts, const unsigned cd_value for(i = 0; i < sizeof(unsigned long long); i++) ((unsigned char *)outbuf)[5+i] = (unsigned char)((minval & ((unsigned long long)0xff << i*8)) >> i*8); +#ifdef H5_CLEAR_MEMORY + /* Zero out remaining, unused bytes */ + /* (Looks like an error in the original determination of how many + * bytes would be needed for parameters. - QAK, 2010/08/19) + */ + HDmemset(outbuf + 13, 0, (size_t)8); +#endif /* H5_CLEAR_MEMORY */ + /* special case: minbits equal to full precision */ if(minbits == p.size * 8) { HDmemcpy(outbuf + buf_offset, *buf, nbytes); |