summaryrefslogtreecommitdiffstats
path: root/src/H5Fsuper.c
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 /src/H5Fsuper.c
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)
Diffstat (limited to 'src/H5Fsuper.c')
-rw-r--r--src/H5Fsuper.c62
1 files changed, 32 insertions, 30 deletions
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)) {