# HG changeset patch # User Rik # Date 1407963974 25200 # Node ID 35097be5007c76a5ffe7d5e1855240cf9482d18c # Parent ed24879107300122b97a4b86340eef70b2ece2db Issue warning rather than segfaulting when failing to reshape Sparse array (bug #42850). * Sparse.cc (reshape): Check whether octave_idx_type (int32 usually) has overflowed and error out of reshape. diff --git a/liboctave/array/Sparse.cc b/liboctave/array/Sparse.cc --- a/liboctave/array/Sparse.cc +++ b/liboctave/array/Sparse.cc @@ -842,6 +842,10 @@ for (octave_idx_type j = cidx (i); j < cidx (i+1); j++) { octave_idx_type tmp = i * old_nr + ridx (j); + if (tmp < 0) + (*current_liboctave_error_handler) + ("reshape: overflow in octave_idx_type prevents reshaping array"); + octave_idx_type ii = tmp % new_nr; octave_idx_type jj = (tmp - ii) / new_nr; for (octave_idx_type k = kk; k < jj; k++)