Mercurial > hg > octave-shane
changeset 16073:1c8234f0b642
Fix bounds-checking in diagonal matrices (bug #38357)
* ov-base-diag.cc (octave_base_diag<DMT, MT>::do_index_op): Call
checkelem instead of elem in the (scalar, scalar) indexing case.
* index.tst: Add tests.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 20 Feb 2013 16:37:02 -0500 |
parents | ac672925fc98 |
children | 821922270b66 |
files | libinterp/octave-value/ov-base-diag.cc test/index.tst |
diffstat | 2 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base-diag.cc +++ b/libinterp/octave-value/ov-base-diag.cc @@ -109,7 +109,7 @@ if (idx0.is_scalar () && idx1.is_scalar ()) { - retval = matrix.elem (idx0(0), idx1(0)); + retval = matrix.checkelem (idx0(0), idx1(0)); } else {
--- a/test/index.tst +++ b/test/index.tst @@ -210,3 +210,20 @@ %!error <attempted to use a complex scalar as an index> x(i) %!error <attempted to use a complex scalar as an index> x(j) %!error <attempted to use a complex scalar as an index> x(1+i) + +## bug #38357 +%!shared d, dd +%! d = diag ([1, 2, 3]); +%! dd = diag ([1, 2, 3], 6, 3); +%!assert (d(1), 1); +%!assert (dd(1), 1); +%!assert (d(3, 3), 3); +%!assert (dd(3, 3), 3); +%!assert (d(2), 0); +%!assert (dd(2), 0); +%!assert (dd(6,1), 0); +%!error d(6,6); +%!error dd(6,6); +%!error d(3,6); +%!error dd(3,6); +