summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-12-13 05:28:30 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-12-13 05:28:30 (GMT)
commit9b2c4bea023c29f5d02f9cbbe6f42f9a96013d82 (patch)
treeaf90885cf55013c15afff145fb5b222a8c622a76
parent5d0fdb855d492fbb9fe217b059c621a109c1e831 (diff)
downloadhdf5-9b2c4bea023c29f5d02f9cbbe6f42f9a96013d82.zip
hdf5-9b2c4bea023c29f5d02f9cbbe6f42f9a96013d82.tar.gz
hdf5-9b2c4bea023c29f5d02f9cbbe6f42f9a96013d82.tar.bz2
[svn-r18011] Description:
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
-rw-r--r--hl/src/H5LT.c22
-rw-r--r--hl/test/test_ds.c1
-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
-rw-r--r--test/pool.c209
-rw-r--r--tools/h5dump/h5dump.c39
-rw-r--r--tools/h5stat/h5stat.c10
-rw-r--r--tools/lib/h5tools.c64
-rw-r--r--tools/lib/h5tools_error.h1
16 files changed, 514 insertions, 445 deletions
diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c
index e797d14..c38d383 100644
--- a/hl/src/H5LT.c
+++ b/hl/src/H5LT.c
@@ -1668,7 +1668,7 @@ print_enum(hid_t type, char* str, int indt)
int nmembs; /*number of members */
char tmp_str[256];
int nchars; /*number of output characters */
- hid_t super; /*enum base integer type */
+ hid_t super = -1; /*enum base integer type */
hid_t native = -1; /*native integer data type */
size_t super_size; /*enum base type size */
size_t dst_size; /*destination value type size */
@@ -1742,21 +1742,35 @@ print_enum(hid_t type, char* str, int indt)
}
/* Release resources */
- for (i = 0; i < nmembs; i++)
+ for(i = 0; i < nmembs; i++)
free(name[i]);
free(name);
free(value);
H5Tclose(super);
- if (0 == nmembs) {
+ if(0 == nmembs) {
sprintf(tmp_str, "\n%*s <empty>", indt + 4, "");
strcat(str, tmp_str);
- }
+ } /* end if */
return ret;
out:
+ /* Release resources */
+ if(name) {
+ for(i = 0; i < nmembs; i++)
+ if(name[i])
+ free(name[i]);
+ free(name);
+ } /* end if */
+
+ if(value)
+ free(value);
+
+ if(super >= 0)
+ H5Tclose(super);
+
return FAIL;
}
diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c
index 7e0f20e..32622ed 100644
--- a/hl/test/test_ds.c
+++ b/hl/test/test_ds.c
@@ -4889,6 +4889,7 @@ static int read_data( const char* fname,
if ( *buf == NULL )
{
printf( "memory allocation failed\n" );
+ fclose(f);
return -1;
}
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\
diff --git a/test/pool.c b/test/pool.c
index 43e9cfd..9b2e8b9 100644
--- a/test/pool.c
+++ b/test/pool.c
@@ -46,14 +46,11 @@
* Purpose: Test trivial creating & closing memory pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -74,18 +71,18 @@ test_create(void)
/* Check free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Check first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -94,7 +91,10 @@ test_create(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_create() */
@@ -105,14 +105,11 @@ error:
* Purpose: Tests closing pool with one block allocated
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -143,7 +140,10 @@ test_close_one(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_close_one() */
@@ -154,14 +154,11 @@ error:
* Purpose: Tests allocating first block in pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -187,29 +184,29 @@ test_allocate_first(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Get first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page == NULL)
TEST_ERROR
/* Check page's free space */
- if (H5MP_get_page_free_size(page, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_free_size(page, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Check next page */
- if (H5MP_get_page_next_page(page, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_next_page(page, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
@@ -217,17 +214,17 @@ test_allocate_first(void)
H5MP_free(mp, spc);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -244,29 +241,29 @@ test_allocate_first(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Get first page */
- if (H5MP_get_pool_first_page(mp, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_first_page(mp, &page) < 0)
+ TEST_ERROR
if(page == NULL)
TEST_ERROR
/* Check page's free space */
- if (H5MP_get_page_free_size(page, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_free_size(page, &free_size) < 0)
+ TEST_ERROR
if(free_size != 0)
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Check next page */
- if (H5MP_get_page_next_page(page, &page) < 0)
- TEST_ERROR;
+ if(H5MP_get_page_next_page(page, &page) < 0)
+ TEST_ERROR
if(page != NULL)
TEST_ERROR
@@ -274,17 +271,17 @@ test_allocate_first(void)
H5MP_free(mp, spc);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -293,7 +290,10 @@ test_allocate_first(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_first() */
@@ -305,14 +305,11 @@ error:
* existing block
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -338,13 +335,13 @@ test_allocate_split(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Allocate more space in pool */
if(NULL == (spc2 = H5MP_malloc(mp, (size_t)MPOOL_NORMAL_BLOCK)))
@@ -352,42 +349,42 @@ test_allocate_split(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * 2) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free first block in pool */
H5MP_free(mp, spc1);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free second block in pool (should merge with first block) */
H5MP_free(mp, spc2);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -396,7 +393,10 @@ test_allocate_split(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_split() */
@@ -407,14 +407,11 @@ error:
* Purpose: Tests allocating many small blocks in a pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Tuesday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -441,13 +438,13 @@ test_allocate_many_small(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_SMALL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_SMALL_BLOCKS) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free blocks in pool */
/* (Tests free block merging with block after it */
@@ -455,17 +452,17 @@ test_allocate_many_small(void)
H5MP_free(mp, spc[i]);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -474,7 +471,10 @@ test_allocate_many_small(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_many_small() */
@@ -486,14 +486,11 @@ error:
* new page
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -522,13 +519,13 @@ test_allocate_new_page(void)
/* Check pool's free space */
if(H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ TEST_ERROR
if(free_size != (MPOOL_PAGE_SIZE * 3) - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_NORMAL_BLOCKS) + (H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)) * 3)))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free blocks in pool */
/* (Free alternating blocks, in two passes, which tests block merging w/both neighbors) */
@@ -538,17 +535,17 @@ test_allocate_new_page(void)
H5MP_free(mp, spc[u]);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) * 3))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -568,32 +565,32 @@ test_allocate_new_page(void)
TEST_ERROR
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Free blocks in pool */
H5MP_free(mp, spc1);
H5MP_free(mp, spc2);
/* Check pool's free space */
- if (H5MP_get_pool_free_size(mp, &free_size) < 0)
- TEST_ERROR;
+ if(H5MP_get_pool_free_size(mp, &free_size) < 0)
+ TEST_ERROR
if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) +
MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))))
TEST_ERROR
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
PASSED();
@@ -602,7 +599,10 @@ test_allocate_new_page(void)
error:
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_new_page() */
@@ -613,14 +613,11 @@ error:
* Purpose: Tests allocating random sized blocks in pool
*
* Return: Success: 0
- *
* Failure: 1
*
* Programmer: Quincey Koziol
* Friday, May 6, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
static int
@@ -640,7 +637,7 @@ test_allocate_random(void)
TESTING("allocate many random sized blocks");
/* Initialize random number seed */
- curr_time=HDtime(NULL);
+ curr_time = HDtime(NULL);
#ifdef QAK
curr_time=1115412944;
HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
@@ -670,7 +667,7 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
/* Check that free space totals match */
if(H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ TEST_ERROR
/* Shuffle pointers to free */
for(u = 0; u < MPOOL_NUM_RANDOM; u++) {
@@ -685,8 +682,8 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
H5MP_free(mp, spc[u]);
/* Check that free space totals match */
- if (H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ if(H5MP_pool_is_free_size_correct(mp) <= 0)
+ TEST_ERROR
/* Initialize the block sizes with random values */
for(u = 0; u < MPOOL_NUM_RANDOM; u++)
@@ -700,10 +697,10 @@ HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
/* Check that free space totals match */
if(H5MP_pool_is_free_size_correct(mp) <= 0)
- TEST_ERROR;
+ TEST_ERROR
/* Close the memory pool */
- if (H5MP_close(mp) < 0)
+ if(H5MP_close(mp) < 0)
TEST_ERROR
/* Free memory for block sizes & pointers */
@@ -720,7 +717,10 @@ error:
if(spc)
HDfree(spc);
H5E_BEGIN_TRY {
+ if(mp)
+ H5MP_close(mp);
} H5E_END_TRY;
+
return 1;
} /* test_allocate_random() */
@@ -731,20 +731,17 @@ error:
* Purpose: Test the memory pool code
*
* Return: Success:
- *
* Failure:
*
* Programmer: Quincey Koziol
* Tuesday, May 3, 2005
*
- * Modifications:
- *
*-------------------------------------------------------------------------
*/
int
main(void)
{
- int nerrors=0;
+ int nerrors = 0;
/* Reset library */
h5_reset();
@@ -762,14 +759,14 @@ main(void)
nerrors += test_allocate_new_page();
nerrors += test_allocate_random();
- if (nerrors) goto error;
+ if(nerrors)
+ goto error;
puts("All memory pool tests passed.");
+
return 0;
error:
puts("*** TESTS FAILED ***");
- H5E_BEGIN_TRY {
- } H5E_END_TRY;
return 1;
}
diff --git a/tools/h5dump/h5dump.c b/tools/h5dump/h5dump.c
index abe97ea..0628299 100644
--- a/tools/h5dump/h5dump.c
+++ b/tools/h5dump/h5dump.c
@@ -2710,11 +2710,12 @@ dump_dcpl(hid_t dcpl_id,hid_t type_id, hid_t obj_id)
int i, next;
unsigned j;
- storage_size=H5Dget_storage_size(obj_id);
+ storage_size = H5Dget_storage_size(obj_id);
nfilters = H5Pget_nfilters(dcpl_id);
- ioffset=H5Dget_offset(obj_id);
- next=H5Pget_external_count(dcpl_id);
- strcpy(f_name,"\0");
+ ioffset = H5Dget_offset(obj_id);
+ next = H5Pget_external_count(dcpl_id);
+ HDassert(next >= 0);
+ HDstrcpy(f_name,"\0");
/*-------------------------------------------------------------------------
* STORAGE_LAYOUT
@@ -4525,14 +4526,16 @@ print_enum(hid_t type)
unsigned char *value = NULL; /*value array */
unsigned char *copy = NULL; /*a pointer to value array */
unsigned nmembs; /*number of members */
+ int snmembs;
int nchars; /*number of output characters */
hid_t super; /*enum base integer type */
hid_t native = -1; /*native integer datatype */
size_t dst_size; /*destination value type size */
unsigned i;
- nmembs = H5Tget_nmembers(type);
- assert(nmembs>0);
+ snmembs = H5Tget_nmembers(type);
+ HDassert(snmembs >= 0);
+ nmembs = (unsigned)snmembs;
super = H5Tget_super(type);
/*
@@ -4542,17 +4545,16 @@ print_enum(hid_t type)
* 2. unsigned long long -- the largest native unsigned integer
* 3. raw format
*/
- if (H5Tget_size(type) <= sizeof(long long)) {
- dst_size = sizeof(long long);
+ if(H5Tget_size(type) <= sizeof(long long)) {
+ dst_size = sizeof(long long);
- if (H5T_SGN_NONE == H5Tget_sign(type)) {
- native = H5T_NATIVE_ULLONG;
- } else {
- native = H5T_NATIVE_LLONG;
- }
- } else {
- dst_size = H5Tget_size(type);
- }
+ if(H5T_SGN_NONE == H5Tget_sign(type))
+ native = H5T_NATIVE_ULLONG;
+ else
+ native = H5T_NATIVE_LLONG;
+ } /* end if */
+ else
+ dst_size = H5Tget_size(type);
/* Get the names and raw values of all members */
name = calloc(nmembs, sizeof(char *));
@@ -6706,13 +6708,16 @@ xml_print_enum(hid_t type)
char **name = NULL; /*member names */
unsigned char *value = NULL; /*value array */
unsigned nmembs; /*number of members */
+ int snmembs;
hid_t super; /*enum base integer type */
hid_t native = -1; /*native integer datatype */
size_t dst_size; /*destination value type size */
unsigned i; /*miscellaneous counters */
size_t j;
- nmembs = H5Tget_nmembers(type);
+ snmembs = H5Tget_nmembers(type);
+ HDassert(snmembs >= 0);
+ nmembs = (unsigned)snmembs;
super = H5Tget_super(type);
indentation(indent);
diff --git a/tools/h5stat/h5stat.c b/tools/h5stat/h5stat.c
index 1b215ff..a4e32f7 100644
--- a/tools/h5stat/h5stat.c
+++ b/tools/h5stat/h5stat.c
@@ -580,10 +580,12 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi)
iter->dset_comptype[0]++;
for(u = 0; u < (unsigned)nfltr; u++) {
fltr = H5Pget_filter2(dcpl, u, 0, 0, 0, 0, 0, NULL);
- if(fltr < (H5_NFILTERS_IMPL - 1))
- iter->dset_comptype[fltr]++;
- else
- iter->dset_comptype[H5_NFILTERS_IMPL - 1]++; /*other filters*/
+ if(fltr >= 0) {
+ if(fltr < (H5_NFILTERS_IMPL - 1))
+ iter->dset_comptype[fltr]++;
+ else
+ iter->dset_comptype[H5_NFILTERS_IMPL - 1]++; /*other filters*/
+ } /* end if */
} /* end for */
} /* endif nfltr */
diff --git a/tools/lib/h5tools.c b/tools/lib/h5tools.c
index 55075a0..8263909 100644
--- a/tools/lib/h5tools.c
+++ b/tools/lib/h5tools.c
@@ -2000,10 +2000,10 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
/* calculate the potential number of elements we're going to print */
if(H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, temp_stride, temp_count, temp_block) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
if((sm_nelmts = H5Sget_select_npoints(f_space)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_npoints failed");
if (sm_nelmts > 0) {
/*
@@ -2011,7 +2011,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
* a hyperslab whose size is manageable.
*/
if((sm_nbytes = p_type_nbytes = H5Tget_size(p_type)) == 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size failed");
if (ctx->ndims > 0)
for (i = ctx->ndims; i > 0; --i) {
@@ -2025,18 +2025,17 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
assert(sm_nbytes == (hsize_t) ((size_t) sm_nbytes)); /*check for overflow*/
if((sm_buf = HDmalloc((size_t) sm_nelmts * p_type_nbytes)) == NULL)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not allocate buffer for strip-mine");
if((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Screate_simple failed");
if(H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, &zero, NULL, &sm_nelmts, NULL) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sselect_hyperslab failed");
/* read the data */
- if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) {
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Dread failed");
- }
+ if(H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Dread failed");
/* print the data */
flags = START_OF_DATA;
@@ -2050,7 +2049,7 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
/* print array indices. get the lower bound of the hyperslab and calulate
the element position at the start of hyperslab */
if(H5Sget_select_bounds(f_space, low, high) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_select_bounds failed");
elmtno = 0;
for (i = 0; i < (size_t) ctx->ndims - 1; i++) {
@@ -2066,10 +2065,11 @@ h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_c
ctx->sm_pos = elmtno;
h5tools_dump_simple_data(stream, info, dset, ctx, flags, sm_nelmts, p_type, sm_buf);
-done:
+
if(H5Sclose(sm_space) < 0)
- HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
- HDfree(sm_buf);
+ H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+ if(sm_buf)
+ HDfree(sm_buf);
}
else
H5E_THROW(SUCCEED, H5E_tools_min_id_g, "nothing to print");
@@ -2272,7 +2272,8 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
hid_t p_type, struct subset_t *sset, int indentlevel)
{
HERR_INIT(herr_t, SUCCEED)
- hid_t f_space; /* file data space */
+ int sndims;
+ hid_t f_space = -1; /* file data space */
size_t i; /* counters */
hsize_t total_size[H5S_MAX_RANK];/* total size of dataset*/
h5tools_context_t ctx; /* print context */
@@ -2288,8 +2289,9 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
memset(&ctx, 0, sizeof(ctx));
ctx.indent_level = indentlevel;
ctx.need_prefix = 1;
- if((ctx.ndims = H5Sget_simple_extent_ndims(f_space)) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ if((sndims = H5Sget_simple_extent_ndims(f_space)) < 0)
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_ndims failed");
+ ctx.ndims = (unsigned)sndims;
/* assume entire data space to be printed */
if (ctx.ndims > 0)
@@ -2297,10 +2299,11 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
ctx.p_min_idx[i] = 0;
if(H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0)
- HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Sget_simple_extent_dims failed");
ctx.size_last_dim = total_size[ctx.ndims - 1];
h5tools_display_simple_subset(stream, info, &ctx, dset, p_type, sset, f_space, total_size);
+
/* Terminate the output */
if (ctx.cur_column) {
fputs(OPT(info->line_suf, ""), stream);
@@ -2308,11 +2311,10 @@ h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, hid_t dset
fputs(OPT(info->line_sep, ""), stream);
}
-done:
- if(H5Sclose(f_space) < 0)
- HERROR(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
-
CATCH
+ if(f_space >= 0 && H5Sclose(f_space) < 0)
+ H5E_THROW(H5E_tools_g, H5E_tools_min_id_g, "H5Sclose failed");
+
return ret_value;
}
@@ -3290,10 +3292,12 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
H5T_sign_t sign_type; /*sign of value type */
size_t type_size; /*value type size */
size_t dst_size; /*destination value type size */
+ int snmembs;
unsigned i;
- if((nmembs = H5Tget_nmembers(type)) < 0)
+ if((snmembs = H5Tget_nmembers(type)) < 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_nmembers failed");
+ nmembs = (unsigned)snmembs;
assert(nmembs > 0);
if((super = H5Tget_super(type)) < 0)
@@ -3301,6 +3305,7 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
if((type_size = H5Tget_size(type)) <= 0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_size(type) failed");
+
/*
* Determine what datatype to use for the native values. To simplify
* things we entertain three possibilities:
@@ -3308,21 +3313,18 @@ h5tools_print_enum(h5tools_str_t *buffer, hid_t type)
* 2. unsigned long long -- the largest native unsigned integer
* 3. raw format
*/
- if (type_size <= sizeof(long long)) {
+ if(type_size <= sizeof(long long)) {
dst_size = sizeof(long long);
if((sign_type = H5Tget_sign(type))<0)
H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tget_sign failed");
- if (H5T_SGN_NONE == sign_type) {
+ if(H5T_SGN_NONE == sign_type)
native = H5T_NATIVE_ULLONG;
- }
- else {
+ else
native = H5T_NATIVE_LLONG;
- }
- }
- else {
+ } /* end if */
+ else
dst_size = type_size;
- }
/* Get the names and raw values of all members */
if((name = calloc(nmembs, sizeof(char *))) == NULL)
@@ -3390,7 +3392,7 @@ CATCH
free(value);
if(super >= 0 && H5Tclose(super) < 0)
- H5E_THROW(FAIL, H5E_tools_min_id_g, "H5Tclose failed");
+ H5E_THROW(FAIL, H5E_tools_min_id_g, "Could not close datatype's super class");
if (0 == nmembs)
h5tools_str_append(buffer, "\n<empty>");
diff --git a/tools/lib/h5tools_error.h b/tools/lib/h5tools_error.h
index 9efe223..da8f03c 100644
--- a/tools/lib/h5tools_error.h
+++ b/tools/lib/h5tools_error.h
@@ -116,3 +116,4 @@ extern hid_t H5E_tools_min_id_g;
#define HGOTO_DONE(ret_val) {ret_value = ret_val; goto done;}
#endif /* H5TOOLS_ERROR_H_ */
+