diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index e86bc82c738..29a765c7daf 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -519,10 +519,19 @@ H5Gmove2(hid_t src_loc_id, const char *src_name, hid_t dst_loc_id, const char *d H5VL_loc_params_t loc_params1; H5VL_object_t *vol_obj2 = NULL; /* Object of dst_id */ H5VL_loc_params_t loc_params2; + H5I_type_t id_type = H5I_BADID; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) + id_type = H5I_get_type(src_loc_id); + if (!(H5I_GROUP == id_type || H5I_FILE == id_type)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid group (or file) ID, src_loc_id"); + + id_type = H5I_get_type(dst_loc_id); + if (!(H5I_GROUP == id_type || H5I_FILE == id_type)) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid group (or file) ID, dst_loc_id"); + /* Set up collective metadata if appropriate */ if (H5CX_set_loc(dst_loc_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set collective metadata read info"); diff --git a/test/links.c b/test/links.c index 6612f56e363..753263ea4be 100644 --- a/test/links.c +++ b/test/links.c @@ -2117,6 +2117,22 @@ test_deprec(hid_t fapl, bool new_format) if (H5Gmove2(file_id, "group2", group1_id, "moved_group2") < 0) FAIL_STACK_ERROR; + /* Test passing in invalid ID */ + H5E_BEGIN_TRY + { + if (H5Gmove2(0, "group2", group1_id, "moved_group2") >= 0) + TEST_ERROR; + } + H5E_END_TRY + + /* Test passing in invalid ID */ + H5E_BEGIN_TRY + { + if (H5Gmove2(file_id, "group2", 0, "moved_group2") >= 0) + TEST_ERROR; + } + H5E_END_TRY + /* Ensure that both groups can be opened */ if (H5Gclose(group2_id) < 0) FAIL_STACK_ERROR;