# HG changeset patch # User Markus Appel # Date 1381020526 -7200 # Node ID d0a197b9962ac575c21dcd9ac1938244ea894c7b # Parent 7ed397c8ca68e6258fca2f46d1e86d90ced44f1b Fix loading of string arrays from 3rd party hdf5 files (bug #38789) * libinterp/octave-value/ov-str-mat.cc(load_hdf5): Use (slen+1) in expressions to preserve enough memory. diff -r 7ed397c8ca68 -r d0a197b9962a libinterp/octave-value/ov-str-mat.cc --- a/libinterp/octave-value/ov-str-mat.cc Fri Oct 11 23:39:54 2013 -0400 +++ b/libinterp/octave-value/ov-str-mat.cc Sun Oct 06 02:48:46 2013 +0200 @@ -676,7 +676,7 @@ { // This is cruft for backward compatiability and easy data // importation - if (rank == 0) + if (rank == 0) //FIXME: Does rank==0 even exist for strings in HDF5? { // a single string: int slen = H5Tget_size (type_hid); @@ -693,7 +693,7 @@ // create datatype for (null-terminated) string // to read into: hid_t st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); + H5Tset_size (st_id, slen+1); if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) { H5Tclose (st_id); @@ -731,12 +731,12 @@ // same physical length (I think), which is // slightly wasteful, but oh well. - OCTAVE_LOCAL_BUFFER (char, s, elements * slen); + OCTAVE_LOCAL_BUFFER (char, s, elements * (slen+1)); // create datatype for (null-terminated) string // to read into: hid_t st_id = H5Tcopy (H5T_C_S1); - H5Tset_size (st_id, slen); + H5Tset_size (st_id, slen+1); if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, s) < 0) { @@ -747,10 +747,10 @@ return false; } - charMatrix chm (elements, slen - 1); + charMatrix chm (elements, slen, ' '); for (hsize_t i = 0; i < elements; ++i) { - chm.insert (s + i*slen, i, 0); + chm.insert (s + i*(slen+1), i, 0); } matrix = chm;