HDFGroup / HDFGroup/hdf5

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

Open
#5,312 2 comments 0 reactions 1 assignee Claimed by @bmribler View on GitHub
Component - C Library
Dominant language
C
Stars
988
Forks
355
Avg merge
4d 2h
Merged PRs (30d)
12

Description

- 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
#include

// 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;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.