changeset 17643:d0a197b9962a

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.
author Markus Appel <masolomaster3000@gmail.com>
date Sun, 06 Oct 2013 02:48:46 +0200
parents 7ed397c8ca68
children ca9a9c0740c5
files libinterp/octave-value/ov-str-mat.cc
diffstat 1 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;