From f267533d2bbd4f7454bde11205aced8558addae6 Mon Sep 17 00:00:00 2001 From: Mario Emmenlauer Date: Wed, 6 May 2026 10:59:24 +0200 Subject: [PATCH] Allow to read an empty dataset in Attribute::read(), even if dimensions mismatch --- include/highfive/bits/H5Attribute_misc.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/highfive/bits/H5Attribute_misc.hpp b/include/highfive/bits/H5Attribute_misc.hpp index 7ad38699..6a160c56 100644 --- a/include/highfive/bits/H5Attribute_misc.hpp +++ b/include/highfive/bits/H5Attribute_misc.hpp @@ -68,6 +68,13 @@ inline T Attribute::read() const { template inline void Attribute::read(T& array) const { const DataSpace& mem_space = getMemSpace(); + auto dims = mem_space.getDimensions(); + + if (mem_space.getElementCount() == 0) { + details::inspector::prepare(array, dims); + return; + } + auto file_datatype = getDataType(); const details::BufferInfo buffer_info( file_datatype, @@ -81,12 +88,6 @@ inline void Attribute::read(T& array) const { << buffer_info.getMaxRank() << "(max)"; throw DataSpaceException(ss.str()); } - auto dims = mem_space.getDimensions(); - - if (mem_space.getElementCount() == 0) { - details::inspector::prepare(array, dims); - return; - } auto r = details::data_converter::get_reader(dims, array, file_datatype); read_raw(r.getPointer(), buffer_info.data_type); @@ -133,7 +134,6 @@ inline void Attribute::write(const T& buffer) { } auto file_datatype = getDataType(); - const details::BufferInfo buffer_info( file_datatype, [this]() -> std::string { return this->getName(); },