diff options
author | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2015-10-01 16:12:02 (GMT) |
---|---|---|
committer | Mohamad Chaarawi <chaarawi@hdfgroup.org> | 2015-10-01 16:12:02 (GMT) |
commit | 8d131aca15bca2d042ef175af5cf5a642d4c1152 (patch) | |
tree | 50a5b1c6dbfd137a0795ca47dc7ee84a6e903101 /src/H5Oefl.c | |
parent | a31524e4aee50324ccbc6707584b1758279f984e (diff) | |
parent | 4dc2218ab5622f81c3dd9d68020ac7357f413c50 (diff) | |
download | hdf5-8d131aca15bca2d042ef175af5cf5a642d4c1152.zip hdf5-8d131aca15bca2d042ef175af5cf5a642d4c1152.tar.gz hdf5-8d131aca15bca2d042ef175af5cf5a642d4c1152.tar.bz2 |
[svn-r27929] merge from trunk.
Diffstat (limited to 'src/H5Oefl.c')
-rw-r--r-- | src/H5Oefl.c | 81 |
1 files changed, 33 insertions, 48 deletions
diff --git a/src/H5Oefl.c b/src/H5Oefl.c index a7ce31a..25ab753 100644 --- a/src/H5Oefl.c +++ b/src/H5Oefl.c @@ -18,7 +18,7 @@ * Tuesday, November 25, 1997 */ -#define H5O_PACKAGE /*suppress error about including H5Opkg */ +#include "H5Omodule.h" /* This source code file is part of the H5O module */ #include "H5private.h" /* Generic Functions */ @@ -96,8 +96,8 @@ H5O_efl_decode(H5F_t *f, hid_t dxpl_id, H5O_t H5_ATTR_UNUSED *open_oh, int version; const char *s = NULL; H5HL_t *heap; - size_t u; /* Local index variable */ - void *ret_value; /* Return value */ + size_t u; /* Local index variable */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT @@ -258,64 +258,47 @@ H5O_efl_copy(const void *_mesg, void *_dest) { const H5O_efl_t *mesg = (const H5O_efl_t *) _mesg; H5O_efl_t *dest = (H5O_efl_t *) _dest; - size_t u; /* Local index variable */ - void *ret_value; /* Return value */ + size_t u; /* Local index variable */ + hbool_t slot_allocated = FALSE; /* Flag to indicate that dynamic allocation has begun */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* check args */ HDassert(mesg); - if(!dest) { - if(NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t)))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message") - if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t)))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots") - } /* end if */ - else if(dest->nalloc < mesg->nalloc) { - H5O_efl_entry_t *temp_slot; /* Temporary pointer to new slot information */ - /* Allocate new 'slot' information */ - if(NULL == (temp_slot = (H5O_efl_entry_t *)H5MM_calloc(mesg->nalloc * sizeof(H5O_efl_entry_t)))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots") + /* Allocate destination message, if necessary */ + if(!dest && NULL == (dest = (H5O_efl_t *)H5MM_calloc(sizeof(H5O_efl_t)))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message") - /* Release old 'slot' information */ - for(u = 0; u < dest->nused; u++) - dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name); - dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot); + /* copy */ + *dest = *mesg; - /* Point to new 'slot' information */ - dest->slot = temp_slot; + /* Deep copy allocated information */ + if(dest->nalloc > 0) { + if(NULL == (dest->slot = (H5O_efl_entry_t *)H5MM_calloc(dest->nalloc * sizeof(H5O_efl_entry_t)))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slots") + slot_allocated = TRUE; + for(u = 0; u < mesg->nused; u++) { + dest->slot[u] = mesg->slot[u]; + if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name))) + HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name") + } /* end for */ } /* end if */ - else { - /* Release old 'slot' information */ - for(u = 0; u < dest->nused; u++) - dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name); - } /* end else */ - dest->heap_addr = mesg->heap_addr; - dest->nalloc = mesg->nalloc; - dest->nused = mesg->nused; - - for(u = 0; u < mesg->nused; u++) { - dest->slot[u] = mesg->slot[u]; - if(NULL == (dest->slot[u].name = H5MM_xstrdup(mesg->slot[u].name))) - HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "can't allocate efl message slot name") - } /* end for */ /* Set return value */ ret_value = dest; done: if(NULL == ret_value) { - if(dest && NULL == _dest) { - if(dest->slot) { - for(u = 0; u < mesg->nused; u++) { - if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name) - dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name); - } /* end for */ - dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot); - } /* end if */ - dest = (H5O_efl_t *)H5MM_xfree(dest); + if(slot_allocated) { + for(u = 0; u < dest->nused; u++) + if(dest->slot[u].name != NULL && dest->slot[u].name != mesg->slot[u].name) + dest->slot[u].name = (char *)H5MM_xfree(dest->slot[u].name); + dest->slot = (H5O_efl_entry_t *)H5MM_xfree(dest->slot); } /* end if */ + if(NULL == _dest) + dest = (H5O_efl_t *)H5MM_xfree(dest); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -389,8 +372,10 @@ H5O_efl_reset(void *_mesg) /* reset */ if(mesg->slot) { - for(u = 0; u < mesg->nused; u++) + for(u = 0; u < mesg->nused; u++) { mesg->slot[u].name = (char *)H5MM_xfree(mesg->slot[u].name); + mesg->slot[u].name_offset = 0; + } /* end for */ mesg->slot = (H5O_efl_entry_t *)H5MM_xfree(mesg->slot); } /* end if */ mesg->heap_addr = HADDR_UNDEF; @@ -460,9 +445,9 @@ H5O_efl_copy_file(H5F_t H5_ATTR_UNUSED *file_src, void *mesg_src, H5F_t *file_ds { H5O_efl_t *efl_src = (H5O_efl_t *) mesg_src; H5O_efl_t *efl_dst = NULL; - H5HL_t *heap = NULL; /* Pointer to local heap for EFL file names */ + H5HL_t *heap = NULL; /* Pointer to local heap for EFL file names */ size_t idx, size, name_offset, heap_size; - void *ret_value; /* Return value */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_TAG(dxpl_id, H5AC__COPIED_TAG, NULL) |