# HG changeset patch # User jwe # Date 1163180086 0 # Node ID 12c50a17f20f34aac1f555416b16003529acedaa # Parent 2ad8962722cc0bb4ae1ed3bc2240213f76bbe198 [project @ 2006-11-10 17:34:45 by jwe] diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2006-11-10 John W. Eaton + + * ov-str-mat.cc (octave_char_matrix_str::load_ascii, + octave_char_matrix_str::load_binary): + Use chMatrix as buffer instead of C string. + 2006-11-09 John W. Eaton * ov-usr-fcn.h (octave_user_function::inline_function): diff --git a/src/ov-str-mat.cc b/src/ov-str-mat.cc --- a/src/ov-str-mat.cc +++ b/src/ov-str-mat.cc @@ -370,10 +370,13 @@ int len; if (extract_keyword (is, "length", len) && len >= 0) { - OCTAVE_LOCAL_BUFFER (char, tmp, len+1); - - if (len > 0 && ! - is.read (tmp, len)) + // Use this instead of a C-style character + // buffer so that we can properly handle + // embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); + + if (len > 0 && ! is.read (ptmp, len)) { error ("load: failed to load string constant"); success = false; @@ -381,12 +384,12 @@ } else { - tmp [len] = '\0'; if (len > max_len) { max_len = len; chm.resize (elements, max_len, 0); } + chm.insert (tmp, i, 0); } } @@ -416,18 +419,19 @@ // This is cruft for backward compatiability, // but relatively harmless. - OCTAVE_LOCAL_BUFFER (char, tmp, len+1); + // Use this instead of a C-style character buffer so + // that we can properly handle embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); - if (len > 0 && ! is.read (tmp, len)) + if (len > 0 && ! is.read (ptmp, len)) { error ("load: failed to load string constant"); } else { - tmp [len] = '\0'; - if (is) - matrix = charMatrix (tmp); + matrix = tmp; else error ("load: failed to load string constant"); } @@ -524,15 +528,15 @@ return false; if (swap) swap_bytes<4> (&len); - OCTAVE_LOCAL_BUFFER (char, btmp, len+1); - if (! is.read (reinterpret_cast (btmp), len)) + charMatrix btmp (1, len); + char *pbtmp = btmp.fortran_vec (); + if (! is.read (pbtmp, len)) return false; if (len > max_len) { max_len = len; chm.resize (elements, max_len, 0); } - btmp [len] = '\0'; chm.insert (btmp, i, 0); } matrix = chm;