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.
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.
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
Close #1329.
I think the original issue why we had this restriction in the first place can be understood from the documentation of
H5Tset_sizein HDF5:This commit switches to using null-terminated strings.