changeset 19042:35097be5007c stable

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.
author Rik <rik@octave.org>
date Wed, 13 Aug 2014 14:06:14 -0700
parents ed2487910730
children c4ffcc961f3c
files liboctave/array/Sparse.cc
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/Sparse.cc	Thu Aug 07 11:41:47 2014 -0400
+++ b/liboctave/array/Sparse.cc	Wed Aug 13 14:06:14 2014 -0700
@@ -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++)