From 90f8fd62f9d8bea9a2dbbea4bb992d98c4f3cc30 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Fri, 24 Nov 2023 11:44:50 +0100 Subject: [PATCH] Fix bug in `enforce_ascii_hack`. (#856) --- include/highfive/bits/H5ReadWrite_misc.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/highfive/bits/H5ReadWrite_misc.hpp b/include/highfive/bits/H5ReadWrite_misc.hpp index c8e736174..6ff914734 100644 --- a/include/highfive/bits/H5ReadWrite_misc.hpp +++ b/include/highfive/bits/H5ReadWrite_misc.hpp @@ -76,8 +76,14 @@ inline void enforce_ascii_hack(const DataType& dst, const DataType& src) { // TEMP. CHANGE: Ensure that the character set is properly configured to prevent // converter issues on HDF5 <=v1.12.0 when loading ASCII strings first. // See https://github.com/HDFGroup/hdf5/issues/544 for further information. - if (H5Tget_cset(src.getId()) == H5T_CSET_ASCII) { - H5Tset_cset(dst.getId(), H5T_CSET_ASCII); + + bool is_dst_string = H5Tget_class(dst.getId()) == H5T_STRING; + bool is_src_string = H5Tget_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); + } } }