Mercurial > hg > octave-nkf
changeset 12984:7626f8934466 stable
correctly resize scanf output for %c formats (bug #34037)
* oct-stream.cc (BEGIN_C_CONVERSION): Resize tmp buffer to number of
characters read.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 22 Aug 2011 20:27:27 -0400 |
parents | 9f3ddb1ff2e3 |
children | 8df8b402797d f217edac2c71 |
files | src/oct-stream.cc test/test_io.m |
diffstat | 2 files changed, 6 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -1521,7 +1521,9 @@ tmp[n++] = static_cast<char> (c); \ \ if (n > 0 && c == EOF) \ - is.clear () + is.clear (); \ + \ + tmp.resize (n) // For a `%s' format, skip initial whitespace and then read until the // next whitespace character or until WIDTH characters have been read.
--- a/test/test_io.m +++ b/test/test_io.m @@ -242,6 +242,9 @@ %% test/octave.test/io/puts-4.m %!error <Invalid call to puts.*> puts (1, 2); +%!assert (sscanf ('123456', '%10c'), '123456') +%!assert (sscanf ('123456', '%10s'), '123456') + %% test/octave.test/io/sscanf-1.m %!test %! [a, b, c] = sscanf ("1.2 3 foo", "%f%d%s", "C");