Warning from GCC's -Walloc-size-larger-than= in H5Location.cpp
My g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0 compiler warns me about a dangerous alloc in
https://github.com/HDFGroup/hdf5/blob/ec0d3411333feb614c913dd970332043f35bf763/c%2B%2B/src/H5Location.cpp#L2001
This is the warning I got:
hdf5/c++/src/H5Location.cpp:2001:46: warning: argument 1 range [9223372036854775809, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
2001 | char *name_C = new char[actual_name_len]();
| ^
In file included from /usr/include/c++/13/bits/exception_ptr.h:38,
from /usr/include/c++/13/exception:164,
from /usr/include/c++/13/ios:41,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from /home/avitase/ravis/core/hdf5/c++/src/H5Location.cpp:13:
/usr/include/c++/13/new:128:26: note: in a call to allocation function ‘void* operator new [](std::size_t)’ declared here
128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
|
Hello! This seemed to be an issue with the C API that was used in the C++ code, and we're working on it. I should let you know that the C++ interface will be discontinued with HDF5 2.0.0, scheduled to be released in March, and there are much better alternatives exist, such as HighFive. Please consider that option.
Thanks for your response and the suggestion to abandon the C++ interface. We considered using HighFive but eventually we decided that for our simple use case relying on yet another third party dependency is not worth it. Am I right that HighFive is not part of HDFGroup or is maintained by you / them?
HighFive is not currently maintained by the HDF Group. The C++ wrappers will probably be removed from the HDF5 library in December or January.
@derobins, thanks for your response. Personally, I find it handy to have a thin C++ wrapper that takes care of the RAII. However, I assume that there are reasons for deprecating the API. Since we cannot easily add dependencies to our project this means that we have to write these wrappers by ourselves, though.
I'm sorry, @avitase, the C++ wrapper has not been maintained for quite a while now. While you write your own wrappers, you're welcome to use the C++ wrapper code in any way if it's helpful.
Hi @avitase, I'm trying to make sure that the call to H5Lget_name_by_idx before 2001 | char *name_C = new char[actual_name_len](); returns a reasonable value for name_len. Could you tell me how you got to that position? If it's your program that calls H5Location::getObjnameByIdx(), would you be able to share the data file? Thanks!
Hi @avitase, I'm trying to make sure that the call to H5Lget_name_by_idx before 2001 | char *name_C = new charactual_name_len; returns a reasonable value for name_len. Could you tell me how you got to that position? If it's your program that calls H5Location::getObjnameByIdx(), would you be able to share the data file? Thanks!
Hi @bmribler, I include HDF5 as a dependency in my CMake super-build. Hence, this error occurs during the compilation of HDF5 itself before seeing my code.
Hi @bmribler, I include HDF5 as a dependency in my CMake super-build. Hence, this error occurs during the compilation of HDF5 itself before seeing my code.
Thanks!
I'm sorry, @avitase, the C++ wrapper has not been maintained for quite a while now. While you write your own wrappers, you're welcome to use the C++ wrapper code in any way if it's helpful.
@avitase I just want to let you know that the removal of the C++ wrapper has been removed from our plan for 2.0. We haven't decided on its long term support yet, but for the time being, it will continue to exist in HDF5 2.0.
@bmribler, thanks for letting me know:)