From bug-octave-request at bevo dot che dot wisc dot edu Mon Dec 17 14:54:03 2001 Subject: Loading .mat file containing variable bound to empty string causes seg fault From: "John W. Eaton" To: Douglas Eck Cc: bug-octave at bevo dot che dot wisc dot edu, doug@ruchetta.idsia.ch Date: Mon, 17 Dec 2001 14:53:21 -0600 On 17-Dec-2001, Douglas Eck wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Cc: doug | Subject: Loading .mat file containing variable bound to empty string causes seg fault | | Bug report for Octave 2.1.35 configured for i386-pc-linux-gnu | | Description: | ----------- | | Loading a .mat file containing variable bound to an empty string causes | segmentation fault. | This does not occur in 2.0.16 | | Repeat-By: | --------- | | Try this: | | mystr=""; | save("foo.mat","mystr") | load("foo.mat") Please try the following patch. Thanks, jwe 2001-12-17 John W. Eaton * data-conv.cc (LS_DO_READ): Don't do anything unless len > 0. (LS_DO_WRITE): Likewise. Index: data-conv.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/data-conv.cc,v retrieving revision 1.13 diff -u -r1.13 data-conv.cc --- data-conv.cc 1 Feb 2000 23:11:59 -0000 1.13 +++ data-conv.cc 17 Dec 2001 20:52:35 -0000 at @ -188,14 +188,17 @@ #define LS_DO_READ(TYPE, swap, data, size, len, stream) \ do \ { \ - volatile TYPE *ptr = X_CAST (volatile TYPE *, data); \ - stream.read (X_CAST (char *, ptr), size * len); \ - if (swap) \ - swap_ ## size ## _bytes (ptr, len); \ - TYPE tmp = ptr[0]; \ - for (int i = len - 1; i > 0; i--) \ - data[i] = ptr[i]; \ - data[0] = tmp; \ + if (len > 0) \ + { \ + volatile TYPE *ptr = X_CAST (volatile TYPE *, data); \ + stream.read (X_CAST (char *, ptr), size * len); \ + if (swap) \ + swap_ ## size ## _bytes (ptr, len); \ + TYPE tmp = ptr[0]; \ + for (int i = len - 1; i > 0; i--) \ + data[i] = ptr[i]; \ + data[0] = tmp; \ + } \ } \ while (0) at @ -205,13 +208,16 @@ #define LS_DO_WRITE(TYPE, data, size, len, stream) \ do \ { \ - char tmp_type = static_cast (type); \ - stream.write (&tmp_type, 1); \ - TYPE *ptr = new TYPE [len]; \ - for (int i = 0; i < len; i++) \ - ptr[i] = X_CAST (TYPE, data[i]); \ - stream.write (X_CAST (char *, ptr), size * len); \ - delete [] ptr ; \ + if (len > 0) \ + { \ + char tmp_type = static_cast (type); \ + stream.write (&tmp_type, 1); \ + TYPE *ptr = new TYPE [len]; \ + for (int i = 0; i < len; i++) \ + ptr[i] = X_CAST (TYPE, data[i]); \ + stream.write (X_CAST (char *, ptr), size * len); \ + delete [] ptr ; \ + } \ } \ while (0) ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------