Mercurial > hg > octave-nkf
changeset 18201:ec87e965c246
allow inputname to work correctly with feval (bug #35497)
* oct-obj.h (octave_value_list::slice): Correct compuation of upper
bound in call to linear_slice for names vector.
* inputname.m: New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 03 Jan 2014 12:52:49 -0500 |
parents | 0ecd4618b1fc |
children | 5646f999245d |
files | libinterp/corefcn/oct-obj.h scripts/miscellaneous/inputname.m |
diffstat | 2 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/oct-obj.h +++ b/libinterp/corefcn/oct-obj.h @@ -107,10 +107,16 @@ octave_value_list slice (octave_idx_type offset, octave_idx_type len, bool tags = false) const { - octave_value_list retval (data.linear_slice (offset, offset + len)); + // linear_slice uses begin/end indices instead of offset and + // length. Avoid calling with upper bound out of range. + // linear_slice handles the case of len < 0. + + octave_value_list retval + = data.linear_slice (offset, std::min (offset + len, length ())); + if (tags && len > 0 && names.length () > 0) - retval.names = names.linear_slice (offset, - std::min (len, names.length ())); + retval.names = names.linear_slice (offset, std::min (offset + len, + names.length ())); return retval; }
--- a/scripts/miscellaneous/inputname.m +++ b/scripts/miscellaneous/inputname.m @@ -57,3 +57,8 @@ %!assert (inputname (1), "hello") %!assert (inputname (2), "worldly") +%!function r = foo (x, y) +%! r = inputname (2); +%!endfunction +%!assert (foo (pi, e), "e"); +%!assert (feval (@foo, pi, e), "e");