# HG changeset patch # User John W. Eaton # Date 1314059247 14400 # Node ID 7626f893446639b7997918f1adab54a1d6e2626a # Parent 9f3ddb1ff2e307a788dc004c84e89b7596d5f5e3 correctly resize scanf output for %c formats (bug #34037) * oct-stream.cc (BEGIN_C_CONVERSION): Resize tmp buffer to number of characters read. diff -r 9f3ddb1ff2e3 -r 7626f8934466 src/oct-stream.cc --- a/src/oct-stream.cc Wed Jul 13 17:53:05 2011 -0700 +++ b/src/oct-stream.cc Mon Aug 22 20:27:27 2011 -0400 @@ -1521,7 +1521,9 @@ tmp[n++] = static_cast (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. diff -r 9f3ddb1ff2e3 -r 7626f8934466 test/test_io.m --- a/test/test_io.m Wed Jul 13 17:53:05 2011 -0700 +++ b/test/test_io.m Mon Aug 22 20:27:27 2011 -0400 @@ -242,6 +242,9 @@ %% test/octave.test/io/puts-4.m %!error 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");