Mercurial > hg > octave-terminal
changeset 9757:95ad9c2a27e2
fix idx_vector construction checks
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 23 Oct 2009 10:35:59 +0200 |
parents | b134960cea23 |
children | 09da0bd91412 |
files | liboctave/ChangeLog liboctave/idx-vector.cc |
diffstat | 2 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2009-10-23 Jaroslav Hajek <highegg@gmail.com> + + * idx-vector.cc (idx_vector::idx_range_rep::idx_range_rep + (octave_idx_type, octave_idx_type, octave_idx_type)): + Improve checking. + 2009-10-21 John W. Eaton <jwe@octave.org> * oct-time.h (octave_time::octave_time (time_t t, int us)):
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -95,14 +95,14 @@ idx_vector::idx_range_rep::idx_range_rep (octave_idx_type _start, octave_idx_type _limit, octave_idx_type _step) - : start(_start), len (_step ? (_limit - _start) / _step : -1), step (_step) + : start(_start), len (_step ? std::max((_limit - _start) / _step, 0) : -1), step (_step) { if (len < 0) { gripe_invalid_range (); err = true; } - else if (start < 0) + else if (start < 0 || (step < 0 && start + (len-1)*step < 0)) { gripe_invalid_index (); err = true; @@ -557,6 +557,8 @@ if (length (0) > 1) retval = elem (1) - elem (0); } + default: + break; } return retval; }