# HG changeset patch # User John W. Eaton # Date 1479914226 18000 # Node ID 86b6f79d4de19998c555dfe4ce839fef51e26efc # Parent f55c208a31c18b750ca599aab28a753c21df9e3b better compatibility for printf with empty args (bug #39375) * oct-stream.cc (printf_value_cache::get_next_value): If argument has no elements, return empty matrix. (octave_base_stream::do_printf): Handle empty matrix in numeric conversion case. * io.tst: New tests. diff -r f55c208a31c1 -r 86b6f79d4de1 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Wed Nov 23 10:07:29 2016 -0500 +++ b/libinterp/corefcn/oct-stream.cc Wed Nov 23 10:17:06 2016 -0500 @@ -5429,9 +5429,13 @@ if (n_elts == 0) { - if (elt_idx == 0 && (type == 's' || type == 'c')) + if (elt_idx == 0) { - retval = ""; + if (type == 's' || type == 'c') + retval = ""; + else + retval = Matrix (); + break; } @@ -5800,8 +5804,11 @@ octave_value val = val_cache.get_next_value (); if (val_cache) - retval += do_numeric_printf_conv (os, elt, nsa, sa_1, - sa_2, val, who); + { + if (! val.is_empty ()) + retval += do_numeric_printf_conv (os, elt, nsa, sa_1, + sa_2, val, who); + } else break; } diff -r f55c208a31c1 -r 86b6f79d4de1 test/io.tst --- a/test/io.tst Wed Nov 23 10:07:29 2016 -0500 +++ b/test/io.tst Wed Nov 23 10:17:06 2016 -0500 @@ -727,3 +727,11 @@ %!assert (sprintf ("%s", repmat ("blah", 2, 1)), "bbllaahh") %!assert (sprintf ("%c", repmat ("blah", 2, 1)), "bbllaahh") %!assert (sprintf ("%c %c %s", repmat ("blah", 2, 1)), "b b llaahh") + +## bug #39735 +%!assert (sprintf ("a %d b", []), "a b") +%!assert (sprintf ("a %d b", ''), "a b") +%!assert (sprintf ("a %d b", ' '), "a 32 b") +%!assert (sprintf ("a %s b", []), "a b") +%!assert (sprintf ("a %s b", ''), "a b") +%!assert (sprintf ("a %s b", ' '), "a b")