From 877a76e4efc800b5dc1f4cacd79497a7074a594c Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Tue, 21 Nov 2023 15:56:10 +0100 Subject: [PATCH] Fix bug in `enforce_ascii_hack`. --- 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); + } } }