summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fortner <nfortne2@hdfgroup.org>2013-09-13 22:03:22 (GMT)
committerNeil Fortner <nfortne2@hdfgroup.org>2013-09-13 22:03:22 (GMT)
commita80cf34324810aa52c97586950606bbfc64b0e37 (patch)
tree18c48cc4e3226fd1c286f90ff72c3a0fc42022dd
parent309f3e7a23805c7be1fb65e00338fea831f977e7 (diff)
downloadhdf5-a80cf34324810aa52c97586950606bbfc64b0e37.zip
hdf5-a80cf34324810aa52c97586950606bbfc64b0e37.tar.gz
hdf5-a80cf34324810aa52c97586950606bbfc64b0e37.tar.bz2
[svn-r24140] Purpose: Remove problematic abandonment of error stack
Description: H5Fis_hdf5 uses H5F_locate_signature to check if the file is hdf5. If it does not locate the signature, H5F_locate_signature would issue an error and return HADDR_UNDEF. H5Fis_hdf5 does not consider it an error if the signature is not found, so it does not issue an error or clear the stack. The filled stack could then cause issues later on. Changed H5F_locate_signature to return herr_t, not issue an error if the signature is not found, and added a parameter for a pointer to the signature address that the function fills in. Tested: jam, koala, ostrich (h5committest)
-rw-r--r--src/H5F.c13
-rw-r--r--src/H5Fpkg.h2
-rw-r--r--src/H5Fsuper.c62
3 files changed, 41 insertions, 36 deletions
diff --git a/src/H5F.c b/src/H5F.c
index 78fe79f..676daef 100644
--- a/src/H5F.c
+++ b/src/H5F.c
@@ -825,22 +825,25 @@ done:
htri_t
H5Fis_hdf5(const char *name)
{
- H5FD_t *file = NULL; /* Low-level file struct */
- htri_t ret_value; /* Return value */
+ H5FD_t *file = NULL; /* Low-level file struct */
+ haddr_t sig_addr; /* Address of hdf5 file signature */
+ htri_t ret_value; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE1("t", "*s", name);
/* Check args and all the boring stuff. */
if(!name || !*name)
- HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "no file name specified")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL, "no file name specified")
/* Open the file at the virtual file layer */
if(NULL == (file = H5FD_open(name, H5F_ACC_RDONLY, H5P_FILE_ACCESS_DEFAULT, HADDR_UNDEF)))
- HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to open file")
+ HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to open file")
/* The file is an hdf5 file if the hdf5 file signature can be found */
- ret_value = (HADDR_UNDEF != H5F_locate_signature(file, H5AC_ind_dxpl_id));
+ if(H5F_locate_signature(file, H5AC_ind_dxpl_id, &sig_addr) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to locate file signature")
+ ret_value = (HADDR_UNDEF != sig_addr);
done:
/* Close the file */
diff --git a/src/H5Fpkg.h b/src/H5Fpkg.h
index 2465222..5d4ca2f 100644
--- a/src/H5Fpkg.h
+++ b/src/H5Fpkg.h
@@ -296,7 +296,7 @@ H5_DLLVAR const H5AC_class_t H5AC_SUPERBLOCK[1];
/* General routines */
H5_DLL herr_t H5F_init(void);
-H5_DLL haddr_t H5F_locate_signature(H5FD_t *file, hid_t dxpl_id);
+H5_DLL herr_t H5F_locate_signature(H5FD_t *file, hid_t dxpl_id, haddr_t *sig_addr);
H5_DLL herr_t H5F_flush(H5F_t *f, hid_t dxpl_id, hbool_t closing);
/* File mount related routines */
diff --git a/src/H5Fsuper.c b/src/H5Fsuper.c
index 8205392..a1c67ec 100644
--- a/src/H5Fsuper.c
+++ b/src/H5Fsuper.c
@@ -100,34 +100,33 @@ H5F_init_super_interface(void)
/*-------------------------------------------------------------------------
- * Function: H5F_locate_signature
+ * Function: H5F_locate_signature
*
- * Purpose: Finds the HDF5 superblock signature in a file. The signature
- * can appear at address 0, or any power of two beginning with
- * 512.
+ * Purpose: Finds the HDF5 superblock signature in a file. The
+ * signature can appear at address 0, or any power of two
+ * beginning with 512.
*
- * Return: Success: The absolute format address of the signature.
- *
- * Failure: HADDR_UNDEF
+ * Return: Success: SUCCEED
+ * Failure: FAIL
*
- * Programmer: Robb Matzke
- * Friday, November 7, 1997
+ * Programmer: Robb Matzke
+ * Friday, November 7, 1997
*
*-------------------------------------------------------------------------
*/
-haddr_t
-H5F_locate_signature(H5FD_t *file, hid_t dxpl_id)
+herr_t
+H5F_locate_signature(H5FD_t *file, hid_t dxpl_id, haddr_t *sig_addr)
{
- haddr_t addr, eoa;
- uint8_t buf[H5F_SIGNATURE_LEN];
- unsigned n, maxpow;
- haddr_t ret_value; /* Return value */
+ haddr_t addr, eoa;
+ uint8_t buf[H5F_SIGNATURE_LEN];
+ unsigned n, maxpow;
+ herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT
/* Find the least N such that 2^N is larger than the file size */
if(HADDR_UNDEF == (addr = H5FD_get_eof(file)) || HADDR_UNDEF == (eoa = H5FD_get_eoa(file, H5FD_MEM_SUPER)))
- HGOTO_ERROR(H5E_IO, H5E_CANTINIT, HADDR_UNDEF, "unable to obtain EOF/EOA value")
+ HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to obtain EOF/EOA value")
for(maxpow = 0; addr; maxpow++)
addr >>= 1;
maxpow = MAX(maxpow, 9);
@@ -137,26 +136,27 @@ H5F_locate_signature(H5FD_t *file, hid_t dxpl_id)
* powers of two larger than 9.
*/
for(n = 8; n < maxpow; n++) {
- addr = (8 == n) ? 0 : (haddr_t)1 << n;
- if(H5FD_set_eoa(file, H5FD_MEM_SUPER, addr + H5F_SIGNATURE_LEN) < 0)
- HGOTO_ERROR(H5E_IO, H5E_CANTINIT, HADDR_UNDEF, "unable to set EOA value for file signature")
- if(H5FD_read(file, dxpl_id, H5FD_MEM_SUPER, addr, (size_t)H5F_SIGNATURE_LEN, buf) < 0)
- HGOTO_ERROR(H5E_IO, H5E_CANTINIT, HADDR_UNDEF, "unable to read file signature")
- if(!HDmemcmp(buf, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN))
+ addr = (8 == n) ? 0 : (haddr_t)1 << n;
+ if(H5FD_set_eoa(file, H5FD_MEM_SUPER, addr + H5F_SIGNATURE_LEN) < 0)
+ HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to set EOA value for file signature")
+ if(H5FD_read(file, dxpl_id, H5FD_MEM_SUPER, addr, (size_t)H5F_SIGNATURE_LEN, buf) < 0)
+ HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to read file signature")
+ if(!HDmemcmp(buf, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN))
break;
} /* end for */
/*
* If the signature was not found then reset the EOA value and return
- * failure.
+ * HADDR_UNDEF.
*/
if(n >= maxpow) {
- (void)H5FD_set_eoa(file, H5FD_MEM_SUPER, eoa); /* Ignore return value */
- HGOTO_ERROR(H5E_IO, H5E_CANTINIT, HADDR_UNDEF, "unable to find a valid file signature")
+ if(H5FD_set_eoa(file, H5FD_MEM_SUPER, eoa) < 0)
+ HGOTO_ERROR(H5E_IO, H5E_CANTINIT, FAIL, "unable to reset EOA value")
+ *sig_addr = HADDR_UNDEF;
} /* end if */
-
- /* Set return value */
- ret_value = addr;
+ else
+ /* Set return value */
+ *sig_addr = addr;
done:
FUNC_LEAVE_NOAPI(ret_value)
@@ -330,8 +330,10 @@ H5F_super_read(H5F_t *f, hid_t dxpl_id)
FUNC_ENTER_NOAPI_TAG(dxpl_id, H5AC__SUPERBLOCK_TAG, FAIL)
/* Find the superblock */
- if(HADDR_UNDEF == (super_addr = H5F_locate_signature(f->shared->lf, dxpl_id)))
- HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to find file signature")
+ if(H5F_locate_signature(f->shared->lf, dxpl_id, &super_addr) < 0)
+ HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "unable to locate file signature")
+ if(HADDR_UNDEF == super_addr)
+ HGOTO_ERROR(H5E_FILE, H5E_NOTHDF5, FAIL, "file signature not found")
/* Check for userblock present */
if(H5F_addr_gt(super_addr, 0)) {