From acf0fea662e69ff8928f055b11183c7a8811fa0e Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 24 Nov 2023 14:17:43 +0100 Subject: [PATCH] Check error code of `?get_cset`. (#861) --- include/highfive/bits/H5ReadWrite_misc.hpp | 10 +++++----- include/highfive/bits/h5t_wrapper.hpp | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/highfive/bits/H5ReadWrite_misc.hpp b/include/highfive/bits/H5ReadWrite_misc.hpp index 6ff914734..4f6f15788 100644 --- a/include/highfive/bits/H5ReadWrite_misc.hpp +++ b/include/highfive/bits/H5ReadWrite_misc.hpp @@ -77,12 +77,12 @@ inline void enforce_ascii_hack(const DataType& dst, const DataType& src) { // converter issues on HDF5 <=v1.12.0 when loading ASCII strings first. // See https://github.com/HDFGroup/hdf5/issues/544 for further information. - bool is_dst_string = H5Tget_class(dst.getId()) == H5T_STRING; - bool is_src_string = H5Tget_class(src.getId()) == H5T_STRING; + bool is_dst_string = detail::h5t_get_class(dst.getId()) == H5T_STRING; + bool is_src_string = detail::h5t_get_class(src.getId()) == H5T_STRING; if (is_dst_string && is_src_string) { - if (H5Tget_cset(src.getId()) == H5T_CSET_ASCII) { - H5Tset_cset(dst.getId(), H5T_CSET_ASCII); + if (detail::h5t_get_cset(src.getId()) == H5T_CSET_ASCII) { + detail::h5t_set_cset(dst.getId(), H5T_CSET_ASCII); } } } @@ -90,7 +90,7 @@ inline void enforce_ascii_hack(const DataType& dst, const DataType& src) { template <> struct string_type_checker { inline static DataType getDataType(const DataType& element_type, const DataType& dtype) { - if (H5Tget_class(element_type.getId()) == H5T_STRING) { + if (detail::h5t_get_class(element_type.getId()) == H5T_STRING) { enforce_ascii_hack(element_type, dtype); } return element_type; diff --git a/include/highfive/bits/h5t_wrapper.hpp b/include/highfive/bits/h5t_wrapper.hpp index debf626bf..a8be1b52b 100644 --- a/include/highfive/bits/h5t_wrapper.hpp +++ b/include/highfive/bits/h5t_wrapper.hpp @@ -59,5 +59,14 @@ inline void h5t_set_strpad(hid_t hid, H5T_str_t strpad) { } } +inline H5T_class_t h5t_get_class(hid_t type_id) { + H5T_class_t class_id = H5Tget_class(type_id); + if (class_id == H5T_NO_CLASS) { + throw DataTypeException("Failed to get class of type"); + } + + return class_id; +} + } // namespace detail } // namespace HighFive