# HG changeset patch # User John W. Eaton # Date 1388771569 18000 # Node ID ec87e965c246cc681b47a7d332147dd5138f526f # Parent 0ecd4618b1fc716f84ec922060c65019ddf660bc 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. diff --git a/libinterp/corefcn/oct-obj.h b/libinterp/corefcn/oct-obj.h --- 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; } diff --git a/scripts/miscellaneous/inputname.m b/scripts/miscellaneous/inputname.m --- 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");