Mercurial > octave
diff liboctave/array/idx-vector.cc @ 31204:a81fad5c9fef
idx_vector: Fix wrong length calculation (bug #62968).
* liboctave/array/idx-vector.cc: Fix wrong calculation for m_len in
(start, limit, step) constructor to account for incomplete intervals.
* liboctave/array/idx-vector.h: Add comment to (start, limit, step) constructor.
author | Maged Rifaat <magedrifaat@gmail.com> |
---|---|
date | Sat, 27 Aug 2022 13:41:44 +0200 |
parents | 796f54d4ddbf |
children | e88a07dec498 |
line wrap: on
line diff
--- a/liboctave/array/idx-vector.cc Fri Aug 26 22:30:43 2022 +0200 +++ b/liboctave/array/idx-vector.cc Sat Aug 27 13:41:44 2022 +0200 @@ -103,8 +103,10 @@ octave_idx_type limit, octave_idx_type step) : idx_base_rep (), m_start(start), - m_len (step ? std::max ((limit - start) / step, - static_cast<octave_idx_type> (0)) + // Round length away from zero to catch incomplete intervals + m_len (step + ? std::max ((limit - start + step - (step > 0 ? 1 : -1)) / step, + static_cast<octave_idx_type> (0)) : -1), m_step (step) {