Mercurial > hg > octave-lojdl
changeset 15724:911a6ad10e9c
fix incorrect sparse array allocation introduced in cda76da34693
* Sparse.h (Sparse<T>::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.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 03 Dec 2012 16:02:30 -0500 |
parents | 77cf1c84db13 |
children | abb92e8951eb |
files | liboctave/array/Sparse.h |
diffstat | 1 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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; }