summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/H5B2.c12
-rw-r--r--test/btree2.c10
2 files changed, 19 insertions, 3 deletions
diff --git a/src/H5B2.c b/src/H5B2.c
index a04a870..828aebd 100644
--- a/src/H5B2.c
+++ b/src/H5B2.c
@@ -2941,6 +2941,9 @@ done:
* OP_DATA pointer, to allow caller to return information about
* the record.
*
+ * If 'OP' is NULL, then this routine just returns "SUCCEED" when
+ * a record is found.
+ *
* Return: Non-negative on success, negative on failure.
*
* Programmer: Quincey Koziol
@@ -2969,7 +2972,6 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
HDassert(f);
HDassert(type);
HDassert(H5F_addr_defined(addr));
- HDassert(op);
/* Look up the B-tree header */
if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_READ)))
@@ -3027,7 +3029,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end if */
else {
/* Make callback for current record */
- if ((op)(H5B2_INT_NREC(internal,shared,idx), op_data) <0) {
+ if ( op && (op)(H5B2_INT_NREC(internal,shared,idx), op_data) <0) {
/* Unlock current node */
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, curr_node_ptr.addr, internal, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
@@ -3073,7 +3075,7 @@ H5B2_find(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
} /* end if */
else {
/* Make callback for current record */
- if ((op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) <0) {
+ if ( op && (op)(H5B2_LEAF_NREC(leaf,shared,idx), op_data) <0) {
/* Unlock current node */
if (H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, curr_node_ptr.addr, leaf, H5AC__NO_FLAGS_SET) < 0)
HGOTO_ERROR(H5E_BTREE, H5E_CANTUNPROTECT, FAIL, "unable to release B-tree node")
@@ -3902,6 +3904,10 @@ H5B2_neighbor(H5F_t *f, hid_t dxpl_id, const H5B2_class_t *type, haddr_t addr,
if (NULL == (bt2 = H5AC_protect(f, dxpl_id, H5AC_BT2_HDR, addr, type, NULL, H5AC_READ)))
HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to load B-tree header")
+ /* Check for empty tree */
+ if(!H5F_addr_defined(bt2->root.addr))
+ HGOTO_ERROR(H5E_BTREE, H5E_NOTFOUND, FAIL, "B-tree has no records")
+
/* Attempt to find neighbor record in B-tree */
if(bt2->depth>0) {
if(H5B2_neighbor_internal(f, dxpl_id, bt2->shared, bt2->depth, &bt2->root, NULL, range, udata, op, op_data)<0)
diff --git a/test/btree2.c b/test/btree2.c
index 80a5714..81d563d 100644
--- a/test/btree2.c
+++ b/test/btree2.c
@@ -223,10 +223,20 @@ test_insert_basic(hid_t fapl)
/* Should fail */
if(ret != FAIL) TEST_ERROR;
+ /* Try again with NULL 'op' */
+ H5E_BEGIN_TRY {
+ ret = H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, NULL, NULL);
+ } H5E_END_TRY;
+ /* Should fail */
+ if(ret != FAIL) TEST_ERROR;
+
/* Attempt to find existant record in B-tree with 1 record */
idx = 42;
if(H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, find_cb, &idx)<0) TEST_ERROR;
+ /* Try again with NULL 'op' */
+ if(H5B2_find(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &idx, NULL, NULL)<0) TEST_ERROR;
+
/* Attempt to index non-existant record in B-tree with 1 record */
idx = 0;
H5E_BEGIN_TRY {