# HG changeset patch # User John W. Eaton # Date 1290069053 18000 # Node ID a117dc8ea1b934ba90f77add3c5698f1383f7440 # Parent 79b77d71d01e6936ee7c2dbc2bf70abf55f7fe83 charMatrix::row_as_string: never strip trailing nul characters diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-11-18 John W. Eaton + + * chMatrix.cc (charMatrix::row_as_string): Never strip trailing + nul characters. Bug #31689. + 2010-11-12 John W. Eaton * Makefile.am (LIBOCTAVE_SOURCES): Delete variable. diff --git a/liboctave/chMatrix.cc b/liboctave/chMatrix.cc --- a/liboctave/chMatrix.cc +++ b/liboctave/chMatrix.cc @@ -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); diff --git a/liboctave/chMatrix.h b/liboctave/chMatrix.h --- a/liboctave/chMatrix.h +++ b/liboctave/chMatrix.h @@ -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 diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2010-11-18 John W. Eaton + + 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 * pt-fcn-handle.cc (tree_anon_fcn_handle::rvalue1): Also stash diff --git a/src/DLD-FUNCTIONS/md5sum.cc b/src/DLD-FUNCTIONS/md5sum.cc --- a/src/DLD-FUNCTIONS/md5sum.cc +++ b/src/DLD-FUNCTIONS/md5sum.cc @@ -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); +*/ + 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 @@ -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 ();