# HG changeset patch # User Maged Rifaat # Date 1661600504 -7200 # Node ID a81fad5c9fef4cf39437ad7d9660cc1eb0a4910b # Parent 4c2b83516eb719e23e11c2701ace432137e59ed6 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. diff -r 4c2b83516eb7 -r a81fad5c9fef liboctave/array/idx-vector.cc --- 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 (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 (0)) : -1), m_step (step) { diff -r 4c2b83516eb7 -r a81fad5c9fef liboctave/array/idx-vector.h --- a/liboctave/array/idx-vector.h Fri Aug 26 22:30:43 2022 +0200 +++ b/liboctave/array/idx-vector.h Sat Aug 27 13:41:44 2022 +0200 @@ -171,7 +171,8 @@ octave_idx_type step, direct) : idx_base_rep (), m_start (start), m_len (len), m_step (step) { } - // Zero-based constructor. + // Zero-based constructor for index range starting at `start` (inclusive) + // and ending at `limit` (exclusive) in steps of `step`. idx_range_rep (octave_idx_type start, octave_idx_type limit, octave_idx_type step);