changeset 6151:12c50a17f20f

[project @ 2006-11-10 17:34:45 by jwe]
author jwe
date Fri, 10 Nov 2006 17:34:46 +0000
parents 2ad8962722cc
children 2eb0723b4fad
files src/ChangeLog src/ov-str-mat.cc
diffstat 2 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Nov 10 00:05:05 2006 +0000
+++ b/src/ChangeLog	Fri Nov 10 17:34:46 2006 +0000
@@ -1,3 +1,9 @@
+2006-11-10  John W. Eaton  <jwe@octave.org>
+
+	* 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  <jwe@octave.org>
 
 	* ov-usr-fcn.h (octave_user_function::inline_function):
--- a/src/ov-str-mat.cc	Fri Nov 10 00:05:05 2006 +0000
+++ b/src/ov-str-mat.cc	Fri Nov 10 17:34:46 2006 +0000
@@ -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<char *> (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;