Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed-size string attributes include \0 in resulting std::string #661

Open
FlyingSamson opened this issue Dec 9, 2024 · 0 comments
Open

Comments

@FlyingSamson
Copy link
Contributor

FlyingSamson commented Dec 9, 2024

When I try to read a fixed-size string attribute with properties (from h5dump -e -a ...) like

ATTRIBUTE "Creator" {
   DATATYPE  H5T_STRING {
      STRSIZE 7;
      STRPAD H5T_STR_NULLTERM;
      CSET H5T_CSET_ASCII;
      CTYPE H5T_C_S1;
   }
   DATASPACE  SCALAR
   DATA {
   (0): "xxxxxx"
   }
}

using code like

std::string value;
attribute.read(value);

the resulting std::string value contains the terminating '\0' character as last character in its internal vector of characters.

I found the related issue #224, and am now unsure if this is intended behavior. I personally find this behavior rather odd and not really conforming to what I expected from an interface storing a string attribute into a std::string.

PS: Reading the same attribute but stored as non-fixed-size string in the hdf5 file

ATTRIBUTE "Creator" {
   DATATYPE  H5T_STRING {
      STRSIZE H5T_VARIABLE;
      STRPAD H5T_STR_NULLTERM;
      CSET H5T_CSET_ASCII;
      CTYPE H5T_C_S1;
   }
   DATASPACE  SCALAR
   DATA {
   (0): "xxxxxx"
   }
}

using the same c++ code, works as expected (i.e., no trailing \0 in the resulting std::string).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant