changeset 11265:a117dc8ea1b9

charMatrix::row_as_string: never strip trailing nul characters
author John W. Eaton <jwe@octave.org>
date Thu, 18 Nov 2010 03:30:53 -0500
parents 79b77d71d01e
children be710ed252ff
files liboctave/ChangeLog liboctave/chMatrix.cc liboctave/chMatrix.h src/ChangeLog src/DLD-FUNCTIONS/md5sum.cc src/ov-str-mat.cc
diffstat 6 files changed, 34 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Wed Nov 17 20:17:10 2010 -0500
+++ b/liboctave/ChangeLog	Thu Nov 18 03:30:53 2010 -0500
@@ -1,3 +1,8 @@
+2010-11-18  John W. Eaton  <jwe@octave.org>
+
+	* chMatrix.cc (charMatrix::row_as_string): Never strip trailing
+	nul characters.  Bug #31689.
+
 2010-11-12  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.am (LIBOCTAVE_SOURCES): Delete variable.
--- a/liboctave/chMatrix.cc	Wed Nov 17 20:17:10 2010 -0500
+++ b/liboctave/chMatrix.cc	Thu Nov 18 03:30:53 2010 -0500
@@ -131,7 +131,7 @@
 }
 
 std::string
-charMatrix::row_as_string (octave_idx_type r, bool strip_ws, bool raw) const 
+charMatrix::row_as_string (octave_idx_type r, bool strip_ws) const 
 {
   std::string retval;
 
@@ -152,22 +152,13 @@
   for (octave_idx_type i = 0; i < nc; i++)
     retval[i] = elem (r, i);
 
-  if (! raw)
+  if (strip_ws)
     {
-      if (strip_ws)
+      while (--nc >= 0)
         {
-          while (--nc >= 0)
-            {
-              char c = retval[nc];
-              if (c && c != ' ')
-                break;
-            }
-        }
-      else
-        {
-          while (--nc >= 0)
-            if (retval[nc])
-              break;
+          char c = retval[nc];
+          if (c && c != ' ')
+            break;
         }
 
       retval.resize (nc+1);
--- a/liboctave/chMatrix.h	Wed Nov 17 20:17:10 2010 -0500
+++ b/liboctave/chMatrix.h	Thu Nov 18 03:30:53 2010 -0500
@@ -69,7 +69,7 @@
   charMatrix& insert (const char *s, octave_idx_type r, octave_idx_type c);
   charMatrix& insert (const charMatrix& a, octave_idx_type r, octave_idx_type c);
 
-  std::string row_as_string (octave_idx_type, bool strip_ws = false, bool raw = false) const;
+  std::string row_as_string (octave_idx_type, bool strip_ws = false) const;
 
   // resize is the destructive equivalent for this one
 
--- a/src/ChangeLog	Wed Nov 17 20:17:10 2010 -0500
+++ b/src/ChangeLog	Thu Nov 18 03:30:53 2010 -0500
@@ -1,3 +1,11 @@
+2010-11-18  John W. Eaton  <jwe@octave.org>
+
+	Bug # 31689.
+
+	* ov-str-mat.cc (octave_char_matrix_str::save_ascii):
+	Adapt to change in charMatrix::row_as_string function.
+	* DLD-FUNCTIONS/md5sum.cc: New tests.
+
 2010-11-17  John W. Eaton  <jwe@octave.org>
 
 	* pt-fcn-handle.cc (tree_anon_fcn_handle::rvalue1): Also stash
--- a/src/DLD-FUNCTIONS/md5sum.cc	Wed Nov 17 20:17:10 2010 -0500
+++ b/src/DLD-FUNCTIONS/md5sum.cc	Thu Nov 18 03:30:53 2010 -0500
@@ -86,3 +86,16 @@
 
   return retval;
 }
+
+/*
+%!assert (md5sum ("abc\0", true), "147a664a2ca9410911e61986d3f0d52a");
+
+%!test
+%! tfile = tmpnam ();
+%! fid = fopen (tfile, "wb");
+%! fwrite (fid, "abc\0");
+%! fclose (fid);
+%! assert (md5sum (tfile), "147a664a2ca9410911e61986d3f0d52a");
+%! unlink (tfile);
+*/
+
--- a/src/ov-str-mat.cc	Wed Nov 17 20:17:10 2010 -0500
+++ b/src/ov-str-mat.cc	Thu Nov 18 03:30:53 2010 -0500
@@ -293,7 +293,7 @@
         {
           unsigned len = chm.cols ();
           os << "# length: " << len << "\n";
-          std::string tstr = chm.row_as_string (i, false, true);
+          std::string tstr = chm.row_as_string (i);
           const char *tmp = tstr.data ();
           if (tstr.length () > len)
             panic_impossible ();