summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-13 12:50:01 (GMT)
commit6c9d003d4ee3bbcaf639149014e8e42ed9835621 (patch)
tree95169b1d25c154882a92b1c68d65c4bc65b04cc9 /src
parent7f46301cee98932ecf7ad87068adc0f5d051d544 (diff)
downloadhdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.zip
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.gz
hdf5-6c9d003d4ee3bbcaf639149014e8e42ed9835621.tar.bz2
[svn-r18013] Description:
Bring r18011 from trunk to 1.8 branch: Bring Coverity changes into the trunk: (also other minor cleanups) r17991: Fix Coverity items 175 and 176. Fixed memory leak on error in print_enum in H5LT.c. r17993: (r17992 was not a Coverity change) Close Coverity issue #206: inconsistently checking whether dt->shared was non-NULL after H5T_alloc() returned a valid 'dt' value (which should guarantee that dt->shared is valid). r17994: Fix Coverity item 149. Fixed file handle leak on error in H5FD_stdio_open. r17995: Fixed Coverity issues 154 to 161: Added H5MP_close routine to error handling in the event *mp has not been freed before error. r17996: Close Coverity issue #126: potentially leaking merged_spans on routine failure. r17997: Fix Coverity items 147 and 148. Fixed resource leaks on error in H5FDloc.c. r17998: Coverity issue 269-272: Added integer result variable to functions that could return negative. Assigned to unsigned after checking. Added H5E_BEGIN_TRY block around H5Tclose and removed H5E_THROW in the catch block. Checked buffer is NULL before free. Changed HGOTO_ERROR outside of the if block to H5E_THROW. r17999: Close Coverity issue #127: release temporary spans in more generic manner. (Also add error checking to previous fix) r18000: Resolved Coverity issues 211 and 212 in H5T.c. Added comments to ignore Coverity warning regarding not checking pointer for NULL, as we are using an assert which catches the issue. r18001: Fix Coverity item 146. Fixed resource leak on error in H5O_layout_copy. r18002: Fix Coverity items 143 and 145. Fixed resource leaks on error in H5D_compact_copy and H5D_contig_copy. r18003: Close Coverity issue #192: close file on error r18004: Fix Coverity issue #125: release temporary spans on error r18005: Resolved Coverity issues 5, 25, and 83 (in H5T.c): Separated embedded functions in order to check for NULL on return of H5I_object before passing into H5T_copy. Check to see if new_dt is NULL within error handling before dereferencing it. Ignore Coverity's dead code warnings as the checks that lead to the code are machine dependent. r18006: Coverity 63,70,73: Checked result of function before assigning to an unsigned variable. r18007: Coverity 78,79: added continue statement if H5Pget_filter2 returns negative. r18008: Fixed Coverity issue # 138: Added support in error handling to free dst pointer (if allocated) on error. r18009: Whitespace & coding style cleanup Tested on: Mac OS X/32 10.6.2 (amazon) w/debug & production (h5committested on trunk)
Diffstat (limited to 'src')
-rw-r--r--src/H5Dcompact.c12
-rw-r--r--src/H5Dcontig.c12
-rw-r--r--src/H5FDlog.c151
-rw-r--r--src/H5FDstdio.c4
-rw-r--r--src/H5Olayout.c8
-rw-r--r--src/H5S.c4
-rw-r--r--src/H5Shyper.c91
-rw-r--r--src/H5T.c328
-rw-r--r--src/H5detect.c3
9 files changed, 330 insertions, 283 deletions
diff --git a/src/H5Dcompact.c b/src/H5Dcompact.c
index edd2fe6..d8bf8b0 100644
--- a/src/H5Dcompact.c
+++ b/src/H5Dcompact.c
@@ -427,16 +427,22 @@ H5D_compact_copy(H5F_t *f_src, H5O_storage_compact_t *storage_src, H5F_t *f_dst,
/* create a memory copy of the variable-length datatype */
if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy")
- if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0)
+ if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) {
+ H5T_close(dt_mem);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register memory datatype")
+ } /* end if */
/* create variable-length datatype at the destinaton file */
if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy")
- if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0)
+ if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "cannot mark datatype on disk")
- if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0)
+ } /* end if */
+ if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype")
+ } /* end if */
/* Set up the conversion functions */
if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem, NULL, NULL, dxpl_id, FALSE)))
diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c
index 282cecb..e2fe420 100644
--- a/src/H5Dcontig.c
+++ b/src/H5Dcontig.c
@@ -1279,16 +1279,22 @@ H5D_contig_copy(H5F_t *f_src, const H5O_storage_contig_t *storage_src,
/* create a memory copy of the variable-length datatype */
if(NULL == (dt_mem = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "unable to copy")
- if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0)
+ if((tid_mem = H5I_register(H5I_DATATYPE, dt_mem, FALSE)) < 0) {
+ H5T_close(dt_mem);
HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register memory datatype")
+ } /* end if */
/* create variable-length datatype at the destinaton file */
if(NULL == (dt_dst = H5T_copy(dt_src, H5T_COPY_TRANSIENT)))
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to copy")
- if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0)
+ if(H5T_set_loc(dt_dst, f_dst, H5T_LOC_DISK) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "cannot mark datatype on disk")
- if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0)
+ } /* end if */
+ if((tid_dst = H5I_register(H5I_DATATYPE, dt_dst, FALSE)) < 0) {
+ H5T_close(dt_dst);
HGOTO_ERROR(H5E_DATASET, H5E_CANTREGISTER, FAIL, "unable to register destination file datatype")
+ } /* end if */
/* Set up the conversion functions */
if(NULL == (tpath_src_mem = H5T_path_find(dt_src, dt_mem, NULL, NULL, dxpl_id, FALSE)))
diff --git a/src/H5FDlog.c b/src/H5FDlog.c
index 051195e..bde63cc 100644
--- a/src/H5FDlog.c
+++ b/src/H5FDlog.c
@@ -409,39 +409,47 @@ done:
* Purpose: Copies the log-specific file access properties.
*
* Return: Success: Ptr to a new property list
- *
* Failure: NULL
*
* Programmer: Quincey Koziol
* Thursday, April 20, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static void *
H5FD_log_fapl_copy(const void *_old_fa)
{
const H5FD_log_fapl_t *old_fa = (const H5FD_log_fapl_t*)_old_fa;
- H5FD_log_fapl_t *new_fa = (H5FD_log_fapl_t *)H5MM_malloc(sizeof(H5FD_log_fapl_t));
+ H5FD_log_fapl_t *new_fa = NULL; /* New FAPL info */
void *ret_value; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_fapl_copy, NULL)
HDassert(new_fa);
+ /* Allocate the new FAPL info */
+ if(NULL == (new_fa = (H5FD_log_fapl_t *)H5MM_calloc(sizeof(H5FD_log_fapl_t))))
+ HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "unable to allocate log file FAPL")
+
/* Copy the general information */
HDmemcpy(new_fa, old_fa, sizeof(H5FD_log_fapl_t));
/* Deep copy the log file name */
- if(old_fa->logfile!=NULL)
- if (NULL==(new_fa->logfile=H5MM_xstrdup(old_fa->logfile)))
+ if(old_fa->logfile != NULL)
+ if(NULL == (new_fa->logfile = H5MM_xstrdup(old_fa->logfile)))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate log file name")
/* Set return value */
- ret_value=new_fa;
+ ret_value = new_fa;
done:
+ if(NULL == ret_value)
+ if(new_fa) {
+ if(new_fa->logfile)
+ H5MM_free(new_fa->logfile);
+ H5MM_free(new_fa);
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_log_fapl_copy() */
@@ -452,21 +460,18 @@ done:
* Purpose: Frees the log-specific file access properties.
*
* Return: Success: 0
- *
* Failure: -1
*
* Programmer: Quincey Koziol
* Thursday, April 20, 2000
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
H5FD_log_fapl_free(void *_fa)
{
H5FD_log_fapl_t *fa = (H5FD_log_fapl_t*)_fa;
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_fapl_free, FAIL)
@@ -488,52 +493,52 @@ done:
* Return: Success: A pointer to a new file data structure. The
* public fields will be initialized by the
* caller, which is always H5FD_open().
- *
* Failure: NULL
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static H5FD_t *
H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
haddr_t maxaddr)
{
- int o_flags;
- int fd=(-1);
- H5FD_log_t *file=NULL;
+ int o_flags;
+ int fd = (-1);
+ H5FD_log_t *file = NULL;
H5FD_log_fapl_t *fa; /* File access property list information */
#ifdef _WIN32
HFILE filehandle;
struct _BY_HANDLE_FILE_INFORMATION fileinfo;
#endif
- h5_stat_t sb;
+ h5_stat_t sb;
H5P_genplist_t *plist; /* Property list */
H5FD_t *ret_value;
FUNC_ENTER_NOAPI(H5FD_log_open, NULL)
/* Check arguments */
- if (!name || !*name)
+ if(!name || !*name)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid file name")
- if (0==maxaddr || HADDR_UNDEF==maxaddr)
+ if(0 == maxaddr || HADDR_UNDEF == maxaddr)
HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, NULL, "bogus maxaddr")
- if (ADDR_OVERFLOW(maxaddr))
+ if(ADDR_OVERFLOW(maxaddr))
HGOTO_ERROR(H5E_ARGS, H5E_OVERFLOW, NULL, "bogus maxaddr")
/* Build the open flags */
o_flags = (H5F_ACC_RDWR & flags) ? O_RDWR : O_RDONLY;
- if (H5F_ACC_TRUNC & flags) o_flags |= O_TRUNC;
- if (H5F_ACC_CREAT & flags) o_flags |= O_CREAT;
- if (H5F_ACC_EXCL & flags) o_flags |= O_EXCL;
+ if(H5F_ACC_TRUNC & flags)
+ o_flags |= O_TRUNC;
+ if(H5F_ACC_CREAT & flags)
+ o_flags |= O_CREAT;
+ if(H5F_ACC_EXCL & flags)
+ o_flags |= O_EXCL;
/* Open the file */
- if ((fd=HDopen(name, o_flags, 0666))<0)
+ if((fd = HDopen(name, o_flags, 0666)) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open file")
- if (HDfstat(fd, &sb)<0)
+ if(HDfstat(fd, &sb) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADFILE, NULL, "unable to fstat file")
/* Create the new file struct */
@@ -541,7 +546,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "unable to allocate file struct")
/* Get the driver specific information */
- if(NULL == (plist = H5P_object_verify(fapl_id,H5P_FILE_ACCESS)))
+ if(NULL == (plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file access property list")
fa = (H5FD_log_fapl_t *)H5P_get_driver_info(plist);
HDassert(fa);
@@ -561,7 +566,7 @@ H5FD_log_open(const char *name, unsigned flags, hid_t fapl_id,
#endif
/* Get the flags for logging */
- file->fa.flags=fa->flags;
+ file->fa.flags = fa->flags;
/* Check if we are doing any logging at all */
if(file->fa.flags != 0) {
@@ -591,6 +596,7 @@ done:
if(NULL == ret_value) {
if(fd >= 0)
HDclose(fd);
+ file = (H5FD_log_t *)H5MM_xfree(file);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -603,14 +609,11 @@ done:
* Purpose: Closes a Unix file.
*
* Return: Success: 0
- *
* Failure: -1, file not closed.
*
* Programmer: Robb Matzke
* Thursday, July 29, 1999
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static herr_t
@@ -621,7 +624,7 @@ H5FD_log_close(H5FD_t *_file)
struct timeval timeval_start,timeval_stop;
struct timeval timeval_diff;
#endif /* H5_HAVE_GETTIMEOFDAY */
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5FD_log_close, FAIL)
@@ -629,7 +632,7 @@ H5FD_log_close(H5FD_t *_file)
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
HDgettimeofday(&timeval_start,NULL);
#endif /* H5_HAVE_GETTIMEOFDAY */
- if (HDclose(file->fd)<0)
+ if(HDclose(file->fd) < 0)
HGOTO_ERROR(H5E_IO, H5E_CANTCLOSEFILE, FAIL, "unable to close file")
#ifdef H5_HAVE_GETTIMEOFDAY
if(file->fa.flags&H5FD_LOG_TIME_CLOSE)
@@ -637,73 +640,73 @@ H5FD_log_close(H5FD_t *_file)
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Dump I/O information */
- if(file->fa.flags!=0) {
+ if(file->fa.flags != 0) {
haddr_t addr;
haddr_t last_addr;
unsigned char last_val;
#ifdef H5_HAVE_GETTIMEOFDAY
- if(file->fa.flags&H5FD_LOG_TIME_CLOSE) {
+ if(file->fa.flags & H5FD_LOG_TIME_CLOSE) {
/* Calculate the elapsed gettimeofday time */
- timeval_diff.tv_usec=timeval_stop.tv_usec-timeval_start.tv_usec;
- timeval_diff.tv_sec=timeval_stop.tv_sec-timeval_start.tv_sec;
- if(timeval_diff.tv_usec<0) {
- timeval_diff.tv_usec+=1000000;
+ timeval_diff.tv_usec = timeval_stop.tv_usec - timeval_start.tv_usec;
+ timeval_diff.tv_sec = timeval_stop.tv_sec - timeval_start.tv_sec;
+ if(timeval_diff.tv_usec < 0) {
+ timeval_diff.tv_usec += 1000000;
timeval_diff.tv_sec--;
} /* end if */
- HDfprintf(file->logfp,"Close took: (%f s)\n",(double)timeval_diff.tv_sec+((double)timeval_diff.tv_usec/(double)1000000.0));
+ HDfprintf(file->logfp, "Close took: (%f s)\n", (double)timeval_diff.tv_sec + ((double)timeval_diff.tv_usec / (double)1000000.0));
} /* end if */
#endif /* H5_HAVE_GETTIMEOFDAY */
/* Dump the write I/O information */
- if(file->fa.flags&H5FD_LOG_FILE_WRITE) {
- HDfprintf(file->logfp,"Dumping write I/O information:\n");
- last_val=file->nwrite[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->nwrite[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
- last_val=file->nwrite[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FILE_WRITE) {
+ HDfprintf(file->logfp, "Dumping write I/O information:\n");
+ last_val = file->nwrite[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->nwrite[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
+ last_val = file->nwrite[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) written to %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) written to %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
} /* end if */
/* Dump the read I/O information */
- if(file->fa.flags&H5FD_LOG_FILE_READ) {
- HDfprintf(file->logfp,"Dumping read I/O information:\n");
- last_val=file->nread[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->nread[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
- last_val=file->nread[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FILE_READ) {
+ HDfprintf(file->logfp, "Dumping read I/O information:\n");
+ last_val = file->nread[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->nread[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
+ last_val = file->nread[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) read from %3d times\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),(int)last_val);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) read from %3d times\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), (int)last_val);
} /* end if */
/* Dump the I/O flavor information */
- if(file->fa.flags&H5FD_LOG_FLAVOR) {
- HDfprintf(file->logfp,"Dumping I/O flavor information:\n");
- last_val=file->flavor[0];
- last_addr=0;
- addr=1;
- while(addr<file->eoa) {
- if(file->flavor[addr]!=last_val) {
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]);
- last_val=file->flavor[addr];
- last_addr=addr;
+ if(file->fa.flags & H5FD_LOG_FLAVOR) {
+ HDfprintf(file->logfp, "Dumping I/O flavor information:\n");
+ last_val = file->flavor[0];
+ last_addr = 0;
+ addr = 1;
+ while(addr < file->eoa) {
+ if(file->flavor[addr] != last_val) {
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]);
+ last_val = file->flavor[addr];
+ last_addr = addr;
} /* end if */
addr++;
} /* end while */
- HDfprintf(file->logfp,"\tAddr %10a-%10a (%10lu bytes) flavor is %s\n",last_addr,(addr-1),(unsigned long)(addr-last_addr),flavors[last_val]);
+ HDfprintf(file->logfp, "\tAddr %10a-%10a (%10lu bytes) flavor is %s\n", last_addr, (addr - 1), (unsigned long)(addr - last_addr), flavors[last_val]);
} /* end if */
/* Free the logging information */
@@ -721,7 +724,7 @@ H5FD_log_close(H5FD_t *_file)
done:
FUNC_LEAVE_NOAPI(ret_value)
-}
+} /* end H5FD_log_close() */
/*-------------------------------------------------------------------------
diff --git a/src/H5FDstdio.c b/src/H5FDstdio.c
index 193c576..7fffbd4 100644
--- a/src/H5FDstdio.c
+++ b/src/H5FDstdio.c
@@ -375,8 +375,10 @@ H5FD_stdio_open( const char *name, unsigned flags, hid_t fapl_id,
H5Epush_ret(func, H5E_ERR_CLS, H5E_IO, H5E_CANTOPENFILE, "fopen failed", NULL)
/* Build the return value */
- if(NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t))))
+ if(NULL == (file = (H5FD_stdio_t *)calloc((size_t)1, sizeof(H5FD_stdio_t)))) {
+ fclose(f);
H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL)
+ } /* end if */
file->fp = f;
file->op = H5FD_STDIO_OP_SEEK;
file->pos = HADDR_UNDEF;
diff --git a/src/H5Olayout.c b/src/H5Olayout.c
index e4257c9..ebae1fb 100644
--- a/src/H5Olayout.c
+++ b/src/H5Olayout.c
@@ -374,8 +374,10 @@ H5O_layout_copy(const void *_mesg, void *_dest)
/* check args */
HDassert(mesg);
+
+ /* Allocate destination message, if necessary */
if(!dest && NULL == (dest = H5FL_MALLOC(H5O_layout_t)))
- HGOTO_ERROR(H5E_OHDR, H5E_NOSPACE, NULL, "memory allocation failed")
+ HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL, "layout message allocation failed")
/* copy */
*dest = *mesg;
@@ -398,6 +400,10 @@ H5O_layout_copy(const void *_mesg, void *_dest)
ret_value = dest;
done:
+ if(ret_value == NULL)
+ if(NULL == _dest)
+ dest = H5FL_FREE(H5O_layout_t, dest);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O_layout_copy() */
diff --git a/src/H5S.c b/src/H5S.c
index c723127..2d1b9db 100644
--- a/src/H5S.c
+++ b/src/H5S.c
@@ -565,6 +565,10 @@ H5S_copy(const H5S_t *src, hbool_t share_selection, hbool_t copy_max)
ret_value = dst;
done:
+ if(NULL == ret_value)
+ if(dst)
+ dst = H5FL_FREE(H5S_t, dst);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5S_copy() */
diff --git a/src/H5Shyper.c b/src/H5Shyper.c
index 21e08d4..f55135f 100644
--- a/src/H5Shyper.c
+++ b/src/H5Shyper.c
@@ -3531,58 +3531,58 @@ done:
herr_t
H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hsize_t *coords)
{
- herr_t ret_value=SUCCEED; /* Return value */
+ herr_t ret_value = SUCCEED; /* Return value */
- FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_add_span_element);
+ FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_add_span_element)
- assert(space);
- assert(rank>0);
- assert(coords);
+ HDassert(space);
+ HDassert(rank > 0);
+ HDassert(coords);
/* Check if this is the first element in the selection */
- if(space->select.sel_info.hslab==NULL) {
+ if(NULL == space->select.sel_info.hslab) {
H5S_hyper_span_info_t *head; /* Pointer to new head of span tree */
/* Allocate a span info node */
- if((head = H5FL_MALLOC(H5S_hyper_span_info_t))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span");
+ if(NULL == (head = H5FL_MALLOC(H5S_hyper_span_info_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span")
/* Set the reference count */
- head->count=1;
+ head->count = 1;
/* Reset the scratch pad space */
- head->scratch=0;
+ head->scratch = 0;
/* Build span tree for this coordinate */
- if((head->head=H5S_hyper_coord_to_span(rank,coords))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span");
+ if(NULL == (head->head = H5S_hyper_coord_to_span(rank, coords)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span")
/* Allocate selection info */
- if((space->select.sel_info.hslab=H5FL_MALLOC(H5S_hyper_sel_t))==NULL)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab info");
+ if(NULL == (space->select.sel_info.hslab = H5FL_MALLOC(H5S_hyper_sel_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab info")
/* Set the selection to the new span tree */
- space->select.sel_info.hslab->span_lst=head;
+ space->select.sel_info.hslab->span_lst = head;
/* Set selection type */
- space->select.type=H5S_sel_hyper;
+ space->select.type = H5S_sel_hyper;
/* Reset "regular" hyperslab flag */
- space->select.sel_info.hslab->diminfo_valid=FALSE;
+ space->select.sel_info.hslab->diminfo_valid = FALSE;
/* Set # of elements in selection */
- space->select.num_elem=1;
+ space->select.num_elem = 1;
} /* end if */
else {
- if(H5S_hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst,rank,coords)<0)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span");
+ if(H5S_hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst,rank,coords) < 0)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span")
/* Increment # of elements in selection */
space->select.num_elem++;
} /* end else */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_add_span_element() */
@@ -4382,13 +4382,13 @@ done:
static herr_t
H5S_hyper_append_span (H5S_hyper_span_t **prev_span, H5S_hyper_span_info_t ** span_tree, hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, H5S_hyper_span_t *next)
{
- H5S_hyper_span_t *new_span;
- herr_t ret_value=SUCCEED; /* Return value */
+ H5S_hyper_span_t *new_span = NULL;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_append_span);
- assert(prev_span);
- assert(span_tree);
+ HDassert(prev_span);
+ HDassert(span_tree);
/* Check for adding first node to merged spans */
if(*prev_span==NULL) {
@@ -4452,7 +4452,13 @@ H5S_hyper_append_span (H5S_hyper_span_t **prev_span, H5S_hyper_span_info_t ** sp
} /* end else */
done:
- FUNC_LEAVE_NOAPI(ret_value);
+ if(ret_value < 0) {
+ if(new_span)
+ if(H5S_hyper_free_span(new_span) < 0)
+ HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "failed to release new hyperslab span")
+ } /* end if */
+
+ FUNC_LEAVE_NOAPI(ret_value)
} /* H5S_hyper_append_span() */
@@ -5264,9 +5270,15 @@ H5S_hyper_merge_spans_helper (H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf
} /* end else */
/* Set return value */
- ret_value=merged_spans;
+ ret_value = merged_spans;
done:
+ if(ret_value == NULL) {
+ if(merged_spans)
+ if(H5S_hyper_free_span_info(merged_spans) < 0)
+ HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, NULL, "failed to release merged hyperslab spans")
+ } /* end if */
+
FUNC_LEAVE_NOAPI(ret_value);
} /* H5S_hyper_merge_spans_helper() */
@@ -5929,14 +5941,6 @@ H5S_generate_hyperslab (H5S_t *space, H5S_seloper_t op,
HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation");
} /* end switch */
- /* Free the hyperslab trees generated from the clipping algorithm */
- if(a_not_b)
- H5S_hyper_free_span_info(a_not_b);
- if(a_and_b)
- H5S_hyper_free_span_info(a_and_b);
- if(b_not_a)
- H5S_hyper_free_span_info(b_not_a);
-
/* Check if the resulting hyperslab span tree is empty */
if(space->select.sel_info.hslab->span_lst==NULL) {
H5S_hyper_span_info_t *spans; /* Empty hyperslab span tree */
@@ -5973,10 +5977,19 @@ H5S_generate_hyperslab (H5S_t *space, H5S_seloper_t op,
} /* end else */
done:
- /* Free the new spans */
- if(new_spans!=NULL)
- if(H5S_hyper_free_span_info(new_spans)<0)
- HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans");
+ /* Free resources */
+ if(a_not_b)
+ if(H5S_hyper_free_span_info(a_not_b) < 0)
+ HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans")
+ if(a_and_b)
+ if(H5S_hyper_free_span_info(a_and_b) < 0)
+ HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans")
+ if(b_not_a)
+ if(H5S_hyper_free_span_info(b_not_a) < 0)
+ HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans")
+ if(new_spans)
+ if(H5S_hyper_free_span_info(new_spans) < 0)
+ HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans")
FUNC_LEAVE_NOAPI(ret_value);
} /* end H5S_generate_hyperslab() */
diff --git a/src/H5T.c b/src/H5T.c
index de917f6..d88aec0 100644
--- a/src/H5T.c
+++ b/src/H5T.c
@@ -2967,66 +2967,71 @@ done:
H5T_t *
H5T_create(H5T_class_t type, size_t size)
{
- H5T_t *dt = NULL;
- hid_t subtype;
- H5T_t *ret_value;
+ H5T_t *dt = NULL;
+ H5T_t *ret_value = NULL;
- FUNC_ENTER_NOAPI(H5T_create, NULL);
+ FUNC_ENTER_NOAPI(H5T_create, NULL)
- switch (type) {
+ switch(type) {
case H5T_INTEGER:
case H5T_FLOAT:
case H5T_TIME:
case H5T_STRING:
case H5T_BITFIELD:
- HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "type class is not appropriate - use H5Tcopy()");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "type class is not appropriate - use H5Tcopy()")
case H5T_OPAQUE:
case H5T_COMPOUND:
if(NULL == (dt = H5T_alloc()))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
dt->shared->type = type;
- if(type==H5T_COMPOUND) {
+ if(type == H5T_COMPOUND) {
dt->shared->u.compnd.packed=FALSE; /* Start out unpacked */
dt->shared->u.compnd.memb_size=0;
} /* end if */
- else if(type==H5T_OPAQUE)
+ else if(type == H5T_OPAQUE)
/* Initialize the tag in case it's not set later. A null tag will
* cause problems for later operations. */
dt->shared->u.opaque.tag = H5MM_strdup("");
break;
case H5T_ENUM:
- if (sizeof(char)==size) {
- subtype = H5T_NATIVE_SCHAR_g;
- } else if (sizeof(short)==size) {
- subtype = H5T_NATIVE_SHORT_g;
- } else if (sizeof(int)==size) {
- subtype = H5T_NATIVE_INT_g;
- } else if (sizeof(long)==size) {
- subtype = H5T_NATIVE_LONG_g;
- } else if (sizeof(long long)==size) {
- subtype = H5T_NATIVE_LLONG_g;
- } else {
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type");
+ {
+ hid_t subtype;
+ H5T_t *sub_t_obj;
+
+ if(sizeof(char) == size)
+ subtype = H5T_NATIVE_SCHAR_g;
+ else if(sizeof(short) == size)
+ subtype = H5T_NATIVE_SHORT_g;
+ else if(sizeof(int) == size)
+ subtype = H5T_NATIVE_INT_g;
+ else if(sizeof(long) == size)
+ subtype = H5T_NATIVE_LONG_g;
+ else if(sizeof(long long) == size)
+ subtype = H5T_NATIVE_LLONG_g;
+ else
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no applicable native integer type")
+ if(NULL == (dt = H5T_alloc()))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
+ dt->shared->type = type;
+ if(NULL == (sub_t_obj = (H5T_t *)H5I_object(subtype)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "unable to get datatype object")
+ if(NULL == (dt->shared->parent = H5T_copy(sub_t_obj, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, NULL, "unable to copy base datatype")
}
- if(NULL == (dt = H5T_alloc()))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
- dt->shared->type = type;
- if (NULL==(dt->shared->parent=H5T_copy(H5I_object(subtype), H5T_COPY_ALL)))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy base data type");
break;
case H5T_VLEN: /* Variable length datatype */
- HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tvlen_create()");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tvlen_create()")
case H5T_ARRAY: /* Array datatype */
- HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tarray_create2()");
+ HGOTO_ERROR(H5E_DATATYPE, H5E_UNSUPPORTED, NULL, "base type required - use H5Tarray_create2()")
default:
- HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class");
- }
+ HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, NULL, "unknown data type class")
+ } /* end switch */
dt->shared->size = size;
@@ -3034,15 +3039,15 @@ H5T_create(H5T_class_t type, size_t size)
ret_value = dt;
done:
- if(ret_value==NULL) {
- if(dt && (dt->shared != NULL))
+ if(NULL == ret_value) {
+ if(dt) {
H5FL_FREE(H5T_shared_t, dt->shared);
- if(dt!=NULL)
H5FL_FREE(H5T_t,dt);
+ } /* end if */
} /* end if */
- FUNC_LEAVE_NOAPI(ret_value);
-}
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5T_create() */
/*-------------------------------------------------------------------------
@@ -3324,10 +3329,11 @@ H5T_copy(const H5T_t *old_dt, H5T_copy_t method)
done:
if(ret_value == NULL) {
- if(new_dt->shared != NULL)
- H5FL_FREE(H5T_shared_t, new_dt->shared);
- if(new_dt != NULL)
+ if(new_dt) {
+ if(new_dt->shared)
+ H5FL_FREE(H5T_shared_t, new_dt->shared);
H5FL_FREE(H5T_t, new_dt);
+ } /* end if */
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
@@ -4273,48 +4279,47 @@ done:
*/
H5T_path_t *
H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
- H5T_conv_t func, hid_t dxpl_id, hbool_t is_api)
+ H5T_conv_t func, hid_t dxpl_id, hbool_t is_api)
{
int lt, rt; /*left and right edges */
int md; /*middle */
int cmp; /*comparison result */
int old_npaths; /* Previous number of paths in table */
- H5T_path_t *table=NULL; /*path existing in the table */
- H5T_path_t *path=NULL; /*new path */
- H5T_path_t *ret_value; /*return value */
- hid_t src_id=-1, dst_id=-1; /*src and dst type identifiers */
+ H5T_path_t *table = NULL; /*path existing in the table */
+ H5T_path_t *path = NULL; /*new path */
+ hid_t src_id = -1, dst_id = -1; /*src and dst type identifiers */
int i; /*counter */
- int nprint=0; /*lines of output printed */
+ int nprint = 0; /*lines of output printed */
+ H5T_path_t *ret_value; /*return value */
FUNC_ENTER_NOAPI(H5T_path_find, NULL);
- assert((!src && !dst) || (src && dst));
+ /* Sanity check */
+ HDassert(src);
+ HDassert(dst);
/*
* Make sure the first entry in the table is the no-op conversion path.
*/
- if (0==H5T_g.npaths) {
- if (NULL==(H5T_g.path=H5MM_malloc(128*sizeof(H5T_path_t*))))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path table");
+ if(0 == H5T_g.npaths) {
+ if(NULL == (H5T_g.path = H5MM_malloc(128 * sizeof(H5T_path_t *))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path table")
H5T_g.apaths = 128;
- if (NULL==(H5T_g.path[0]=H5FL_CALLOC(H5T_path_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for no-op conversion path");
+ if(NULL == (H5T_g.path[0] = H5FL_CALLOC(H5T_path_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for no-op conversion path")
HDstrcpy(H5T_g.path[0]->name, "no-op");
H5T_g.path[0]->func = H5T_conv_noop;
H5T_g.path[0]->cdata.command = H5T_CONV_INIT;
- if (H5T_conv_noop(FAIL, FAIL, &(H5T_g.path[0]->cdata),
- (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id)<0) {
+ if(H5T_conv_noop(FAIL, FAIL, &(H5T_g.path[0]->cdata), (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id) < 0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
- fprintf(H5DEBUG(T), "H5T: unable to initialize no-op "
- "conversion function (ignored)\n");
- }
+ if(H5DEBUG(T))
+ fprintf(H5DEBUG(T), "H5T: unable to initialize no-op conversion function (ignored)\n");
#endif
H5E_clear_stack(NULL); /*ignore the error*/
- }
+ } /* end if */
H5T_g.path[0]->is_noop = TRUE;
H5T_g.npaths = 1;
- }
+ } /* end if */
/*
* Find the conversion path. If source and destination types are equal
@@ -4325,35 +4330,36 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* Only allow the no-op conversion to occur if no "force conversion" flags
* are set
*/
- if (src->shared->force_conv==FALSE && dst->shared->force_conv==FALSE && 0==H5T_cmp(src, dst, TRUE)) {
+ if(src->shared->force_conv == FALSE && dst->shared->force_conv == FALSE && 0 == H5T_cmp(src, dst, TRUE)) {
table = H5T_g.path[0];
cmp = 0;
md = 0;
- } else {
+ } /* end if */
+ else {
lt = md = 1;
rt = H5T_g.npaths;
cmp = -1;
- while (cmp && lt<rt) {
- md = (lt+rt) / 2;
- assert(H5T_g.path[md]);
+ while(cmp && lt < rt) {
+ md = (lt + rt) / 2;
+ HDassert(H5T_g.path[md]);
cmp = H5T_cmp(src, H5T_g.path[md]->src, FALSE);
- if (0==cmp) cmp = H5T_cmp(dst, H5T_g.path[md]->dst, FALSE);
- if (cmp<0) {
+ if(0 == cmp)
+ cmp = H5T_cmp(dst, H5T_g.path[md]->dst, FALSE);
+ if(cmp < 0)
rt = md;
- } else if (cmp>0) {
- lt = md+1;
- } else {
+ else if(cmp > 0)
+ lt = md + 1;
+ else
table = H5T_g.path[md];
- }
- }
- }
+ } /* end while */
+ } /* end else */
/* Keep a record of the number of paths in the table, in case one of the
* initialization calls below (hard or soft) causes more entries to be
* added to the table - QAK, 1/26/02
*/
- old_npaths=H5T_g.npaths;
+ old_npaths = H5T_g.npaths;
/*
* If we didn't find the path, if the caller is an API function specifying
@@ -4361,21 +4367,22 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* specifying a new hard conversion and the path is a soft conversion, then
* create a new path and add the new function to the path.
*/
- if (!table || (table && func && is_api) || (table && !table->is_hard && func && !is_api)) {
- if (NULL==(path=H5FL_CALLOC(H5T_path_t)))
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path");
- if (name && *name) {
+ if(!table || (table && func && is_api) || (table && !table->is_hard && func && !is_api)) {
+ if(NULL == (path = H5FL_CALLOC(H5T_path_t)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for type conversion path")
+ if(name && *name) {
HDstrncpy(path->name, name, (size_t)H5T_NAMELEN);
- path->name[H5T_NAMELEN-1] = '\0';
- } else {
+ path->name[H5T_NAMELEN - 1] = '\0';
+ } /* end if */
+ else
HDstrcpy(path->name, "NONAME");
- }
- if ((src && NULL==(path->src=H5T_copy(src, H5T_COPY_ALL))) ||
- (dst && NULL==(path->dst=H5T_copy(dst, H5T_COPY_ALL))))
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy data type for conversion path");
- } else {
+ if(NULL == (path->src = H5T_copy(src, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy datatype for conversion path")
+ if(NULL == (path->dst = H5T_copy(dst, H5T_COPY_ALL)))
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to copy datatype for conversion path")
+ } /* end if */
+ else
path = table;
- }
/*
* If a hard conversion function is specified and none is defined for the
@@ -4383,25 +4390,24 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* the existing path is a soft function, then add the new conversion to the path
* and initialize its conversion data.
*/
- if (func && (!table || (table && is_api) || (table && !table->is_hard && !is_api))) {
- assert(path!=table);
- assert(NULL==path->func);
- if (path->src && (src_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->src, H5T_COPY_ALL), FALSE))<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register source conversion type for query");
- if (path->dst && (dst_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->dst, H5T_COPY_ALL), FALSE))<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register destination conversion type for query");
+ if(func && (!table || (table && is_api) || (table && !table->is_hard && !is_api))) {
+ HDassert(path != table);
+ HDassert(NULL == path->func);
+ if(path->src && (src_id = H5I_register(H5I_DATATYPE, H5T_copy(path->src, H5T_COPY_ALL), FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register source conversion type for query")
+ if(path->dst && (dst_id = H5I_register(H5I_DATATYPE, H5T_copy(path->dst, H5T_COPY_ALL), FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register destination conversion type for query")
path->cdata.command = H5T_CONV_INIT;
- if ((func)(src_id, dst_id, &(path->cdata), (size_t)0, (size_t)0, (size_t)0,
- NULL, NULL, dxpl_id)<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to initialize conversion function");
- if (src_id>=0) H5I_dec_ref(src_id, FALSE);
- if (dst_id>=0) H5I_dec_ref(dst_id, FALSE);
+ if((func)(src_id, dst_id, &(path->cdata), (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "unable to initialize conversion function")
+ if(src_id >= 0)
+ H5I_dec_ref(src_id, FALSE);
+ if(dst_id >= 0)
+ H5I_dec_ref(dst_id, FALSE);
src_id = dst_id = -1;
path->func = func;
path->is_hard = TRUE;
- }
+ } /* end if */
/*
* If the path doesn't have a function by now (because it's a new path
@@ -4409,116 +4415,118 @@ H5T_path_find(const H5T_t *src, const H5T_t *dst, const char *name,
* for an applicable function and add it to the path. This can't happen
* for the no-op conversion path.
*/
- assert(path->func || (src && dst));
- for (i=H5T_g.nsoft-1; i>=0 && !path->func; --i) {
- if (src->shared->type!=H5T_g.soft[i].src ||
- dst->shared->type!=H5T_g.soft[i].dst) {
+ HDassert(path->func || (src && dst));
+ for(i = H5T_g.nsoft - 1; i >= 0 && !path->func; --i) {
+ if(src->shared->type != H5T_g.soft[i].src || dst->shared->type != H5T_g.soft[i].dst)
continue;
- }
- if ((src_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->src, H5T_COPY_ALL), FALSE))<0 ||
- (dst_id=H5I_register(H5I_DATATYPE,
- H5T_copy(path->dst, H5T_COPY_ALL), FALSE))<0)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register conversion types for query");
+ if((src_id = H5I_register(H5I_DATATYPE, H5T_copy(path->src, H5T_COPY_ALL), FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register src conversion type for query")
+ if((dst_id = H5I_register(H5I_DATATYPE, H5T_copy(path->dst, H5T_COPY_ALL), FALSE)) < 0)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTREGISTER, NULL, "unable to register dst conversion type for query")
path->cdata.command = H5T_CONV_INIT;
- if ((H5T_g.soft[i].func) (src_id, dst_id, &(path->cdata),
- (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id)<0) {
- HDmemset (&(path->cdata), 0, sizeof(H5T_cdata_t));
+ if((H5T_g.soft[i].func)(src_id, dst_id, &(path->cdata), (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id) < 0) {
+ HDmemset(&(path->cdata), 0, sizeof(H5T_cdata_t));
H5E_clear_stack(NULL); /*ignore the error*/
- } else {
- HDstrcpy (path->name, H5T_g.soft[i].name);
+ } /* end if */
+ else {
+ HDstrcpy(path->name, H5T_g.soft[i].name);
path->func = H5T_g.soft[i].func;
path->is_hard = FALSE;
- }
+ } /* end else */
H5I_dec_ref(src_id, FALSE);
H5I_dec_ref(dst_id, FALSE);
src_id = dst_id = -1;
- }
- if (!path->func)
- HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no appropriate function for conversion path");
+ } /* end for */
+ if(!path->func)
+ HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "no appropriate function for conversion path")
/* Check if paths were inserted into the table through a recursive call
* and re-compute the correct location for this path if so. - QAK, 1/26/02
*/
- if(old_npaths!=H5T_g.npaths) {
+ if(old_npaths != H5T_g.npaths) {
lt = md = 1;
rt = H5T_g.npaths;
cmp = -1;
- while (cmp && lt<rt) {
- md = (lt+rt) / 2;
- assert(H5T_g.path[md]);
+ while(cmp && lt < rt) {
+ md = (lt + rt) / 2;
+ HDassert(H5T_g.path[md]);
cmp = H5T_cmp(src, H5T_g.path[md]->src, FALSE);
- if (0==cmp) cmp = H5T_cmp(dst, H5T_g.path[md]->dst, FALSE);
- if (cmp<0) {
+ if(0 == cmp)
+ cmp = H5T_cmp(dst, H5T_g.path[md]->dst, FALSE);
+ if(cmp < 0)
rt = md;
- } else if (cmp>0) {
- lt = md+1;
- } else {
+ else if(cmp > 0)
+ lt = md + 1;
+ else
table = H5T_g.path[md];
- }
- }
+ } /* end while */
} /* end if */
/* Replace an existing table entry or add a new entry */
- if (table && path!=table) {
- assert(table==H5T_g.path[md]);
+ if(table && path != table) {
+ HDassert(table == H5T_g.path[md]);
H5T_print_stats(table, &nprint/*in,out*/);
table->cdata.command = H5T_CONV_FREE;
- if ((table->func)(FAIL, FAIL, &(table->cdata), (size_t)0, (size_t)0, (size_t)0,
- NULL, NULL, dxpl_id)<0) {
+ if((table->func)(FAIL, FAIL, &(table->cdata), (size_t)0, (size_t)0, (size_t)0, NULL, NULL, dxpl_id) < 0) {
#ifdef H5T_DEBUG
- if (H5DEBUG(T)) {
+ if(H5DEBUG(T)) {
fprintf(H5DEBUG(T), "H5T: conversion function 0x%08lx free "
"failed for %s (ignored)\n",
(unsigned long)(path->func), path->name);
- }
+ } /* end if */
#endif
H5E_clear_stack(NULL); /*ignore the failure*/
- }
- if (table->src) H5T_close(table->src);
- if (table->dst) H5T_close(table->dst);
- H5FL_FREE(H5T_path_t,table);
+ } /* end if */
+ if(table->src)
+ H5T_close(table->src);
+ if(table->dst)
+ H5T_close(table->dst);
+ H5FL_FREE(H5T_path_t, table);
table = path;
H5T_g.path[md] = path;
- } else if (path!=table) {
- assert(cmp);
- if (H5T_g.npaths >= H5T_g.apaths) {
+ } else if(path != table) {
+ HDassert(cmp);
+ if(H5T_g.npaths >= H5T_g.apaths) {
size_t na = MAX(128, 2 * H5T_g.apaths);
- H5T_path_t **x = H5MM_realloc (H5T_g.path,
- na*sizeof(H5T_path_t*));
- if (!x)
- HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed");
+ H5T_path_t **x = H5MM_realloc (H5T_g.path, na * sizeof(H5T_path_t*));
+
+ if(!x)
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
H5T_g.apaths = (int)na;
H5T_g.path = x;
- }
- if (cmp>0) md++;
- HDmemmove(H5T_g.path+md+1, H5T_g.path+md,
- (H5T_g.npaths-md) * sizeof(H5T_path_t*));
+ } /* end if */
+ if(cmp > 0)
+ md++;
+ HDmemmove(H5T_g.path + md + 1, H5T_g.path + md, (H5T_g.npaths - md) * sizeof(H5T_path_t*));
H5T_g.npaths++;
H5T_g.path[md] = path;
table = path;
- }
+ } /* end else-if */
/* Set the flag to indicate both source and destination types are compound types
* for the optimization of data reading (in H5Dio.c). */
- if(H5T_COMPOUND==H5T_get_class(src, TRUE) && H5T_COMPOUND==H5T_get_class(dst, TRUE))
+ if(H5T_COMPOUND == H5T_get_class(src, TRUE) && H5T_COMPOUND == H5T_get_class(dst, TRUE))
path->are_compounds = TRUE;
/* Set return value */
ret_value = path;
done:
- if (!ret_value && path && path!=table) {
- if (path->src) H5T_close(path->src);
- if (path->dst) H5T_close(path->dst);
- H5FL_FREE(H5T_path_t,path);
- }
- if (src_id>=0) H5I_dec_ref(src_id, FALSE);
- if (dst_id>=0) H5I_dec_ref(dst_id, FALSE);
+ if(!ret_value && path && path != table) {
+ if(path->src)
+ H5T_close(path->src);
+ if(path->dst)
+ H5T_close(path->dst);
+ H5FL_FREE(H5T_path_t, path);
+ } /* end if */
+ if(src_id >= 0)
+ H5I_dec_ref(src_id, FALSE);
+ if(dst_id >= 0)
+ H5I_dec_ref(dst_id, FALSE);
FUNC_LEAVE_NOAPI(ret_value);
-}
+} /* end H5T_path_find() */
/*-------------------------------------------------------------------------
diff --git a/src/H5detect.c b/src/H5detect.c
index f76f159..ebd042d 100644
--- a/src/H5detect.c
+++ b/src/H5detect.c
@@ -821,8 +821,7 @@ H5TN_init_interface(void)\n\
done:\n\
if(ret_value < 0) {\n\
if(dt != NULL) {\n\
- if(dt->shared != NULL)\n\
- H5FL_FREE(H5T_shared_t, dt->shared);\n\
+ H5FL_FREE(H5T_shared_t, dt->shared);\n\
dt = H5FL_FREE(H5T_t, dt);\n\
} /* end if */\n\
} /* end if */\n\