-
Notifications
You must be signed in to change notification settings - Fork 51
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
Enable empty string attributes #1338
Enable empty string attributes #1338
Conversation
max_len = std::max(max_len, s.size()); | ||
std::unique_ptr<char[]> c_str(new char[max_len * vs.size()]); | ||
max_len = std::max(max_len, s.size() + 1); | ||
std::unique_ptr<char[]> c_str(new char[max_len * vs.size()]()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subtle bug fixed in HDF5IOHandler writeAttribute() method:
new char[…]
does not initialize the memory, but strncopy
will copy until either a NULL is found or the max_len
has been reached, so the uninitialized memory is always guarded from actually being read into a std::string
. Also, no segfault is triggered, since the memory left and right of the uninitialized memory is written and the virtual memory can detect no illegal access in that case.
Before this PR, a std::vector{"VECTOR", "OF", "STRINGS"}
was converted to the following c_str
buffer:
VECTOR0
OF0****
STRINGS
where 0 is a null terminator and * is uninitialized memory. The null terminator is missing for the longest string, all other strings have one null terminator, followed by uninitialized memory.
With this PR, it is converted to:
VECTOR00
OF000000
STRINGS0
Every line has at least one null terminator, and the rest of the line is also padded with nulls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks a lot for the fix and explanation.
Hmm, ADIOS1 seems to not like it. We are deprecating that anyway, but may I can find a solution even. |
48b9266
to
dec3c06
Compare
dec3c06
to
2519fac
Compare
2519fac
to
112a933
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks a lot!
Close #1329.
I think the original issue why we had this restriction in the first place can be understood from the documentation of
H5Tset_size
in HDF5:This commit switches to using null-terminated strings.