Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5Piterate returns status as 0 (success) even if the starting location is beyond the last index. #5312

Open
abhibaruah opened this issue Feb 11, 2025 · 0 comments
Assignees

Comments

@abhibaruah
Copy link

  • HDF5 version: 1.14.4.3
  • OS and version: Debian 12
  • Compiler and version: g++

I am using H5P.iterate to iterate over faplID (H5Pcreate(H5P_FILE_ACCESS)). See the repro code below.
In the iterate function, I am simply printing the name of the function.

If the starting index is 0 or NULL, 38 values are printed and the index is updated to 38, which indicates that there are 38 properties.

In the next run of the program, I modify the starting index to 40 which is a bad starting index since it is beyond the number of properties.
Ideally this should have errored out, but the status value returned by H5Piterate is 0, indicating success. The idx value is updated to 38.

Shouldn't there be an error status code returned if the starting index is beyond the last available index?

#include <iostream>
#include <hdf5.h>

// Callback function for iterating over properties
herr_t prop_iter_func(hid_t loc_id, const char *name, void *op_data) {
    std::cout << name << std::endl;
    return 0; // Continue iteration
}

int main() {
    // Create a file access property list
    hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
    if (fapl < 0) {
        std::cerr << "Failed to create property list." << std::endl;
        return -1;
    }

    // Iterate over properties
    int idxOut = 40; // Starting index for iteration
    herr_t status = H5Piterate(fapl, &idxOut, prop_iter_func, NULL);
	
	std::cout << "Status: " << status << std::endl;
	std::cout << "IdxOut: " << idxOut << std::endl;
    if (status < 0) {
        std::cerr << "Failed to iterate over properties." << std::endl;
        H5Pclose(fapl);
        return -1;
    }

    // Close the property list
    H5Pclose(fapl);

    return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants