# HG changeset patch # User David Bateman # Date 1337385561 -7200 # Node ID 8d2ce821e38a4af3c79d9392ea430f01fa8c85cc # Parent 43db83eff9dbe7100c684cd2f8c6e39c98ca888d Ensure sparse constructors have valid ridx and data indices even if they are zero matrices (bug #36104) diff -r 43db83eff9db -r 8d2ce821e38a liboctave/Sparse.cc --- a/liboctave/Sparse.cc Sat May 19 00:14:59 2012 +0200 +++ b/liboctave/Sparse.cc Sat May 19 01:59:21 2012 +0200 @@ -235,7 +235,7 @@ (*current_liboctave_error_handler) ("Sparse::Sparse (const dim_vector&): dimension mismatch"); else - rep = new typename Sparse::SparseRep (dv(0), dv(1)); + rep = new typename Sparse::SparseRep (dv(0), dv(1), 0); } template @@ -301,11 +301,10 @@ (*current_liboctave_error_handler) ("sparse: column index %d out of bound %d", r.extent (nc), nc); - rep = new SparseRep (nr, nc); + rep = new typename Sparse::SparseRep (nr, nc, (nzm > 0 ? nzm : 0)); dimensions = dim_vector (nr, nc); - octave_idx_type n = a.numel (), rl = r.length (nr), cl = c.length (nc); bool a_scalar = n == 1; if (a_scalar) @@ -324,6 +323,7 @@ if (n == 1 && a(0) != T ()) { change_capacity (nzm > 1 ? nzm : 1); + xcidx(0) = 0; xridx(0) = r(0); xdata(0) = a(0); for (octave_idx_type j = 0; j < nc; j++) @@ -352,6 +352,7 @@ new_nz += rd[i-1] != rd[i]; // Allocate result. change_capacity (nzm > new_nz ? nzm : new_nz); + xcidx (0) = 0; xcidx (1) = new_nz; octave_idx_type *rri = ridx (); T *rrd = data (); @@ -494,6 +495,7 @@ new_nz += rd[i-1] != rd[i]; // Allocate result. change_capacity (nzm > new_nz ? nzm : new_nz); + xcidx(0) = 0; xcidx(1) = new_nz; octave_idx_type *rri = ridx (); T *rrd = data ();