# HG changeset patch # User John W. Eaton # Date 1354568550 18000 # Node ID 911a6ad10e9cbb8d1e394337074ca938e1dcf323 # Parent 77cf1c84db132ec2724f3770bdddc7191debfc8f fix incorrect sparse array allocation introduced in cda76da34693 * Sparse.h (Sparse::SparseRep::SparseRep (octave_idx_type, octave_idx_type, octave_idx_type)): Don't allocate D or R arrays if NZ is 0. Initialize all elements of C to 0. diff --git a/liboctave/array/Sparse.h b/liboctave/array/Sparse.h --- a/liboctave/array/Sparse.h +++ b/liboctave/array/Sparse.h @@ -87,12 +87,12 @@ } SparseRep (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz = 0) - : d (new T [nz]), r (new octave_idx_type [nz]), + : d (nz > 0 ? new T [nz] : 0), + r (nz > 0 ? new octave_idx_type [nz] : 0), c (new octave_idx_type [nc+1]), nzmx (nz), nrows (nr), ncols (nc), count (1) { - c[nc] = nz; - for (octave_idx_type i = 0; i < nc; i++) + for (octave_idx_type i = 0; i < nc + 1; i++) c[i] = 0; }