Mercurial > hg > octave-avbm
changeset 6101:9e70afeb2ebf
[project @ 2006-10-26 18:44:02 by jwe]
author | jwe |
---|---|
date | Thu, 26 Oct 2006 18:44:02 +0000 |
parents | 8137e2bbd1dd |
children | ef9569e10d8b |
files | liboctave/ChangeLog liboctave/Sparse.cc |
diffstat | 2 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2006-10-26 David Bateman <dbateman@free.fr> + + * Sparse.cc (Sparse<T>::resize_no_fill (octave_idx_type, + octave_idx_type)): Be more careful with the size of the input + matrix, and therefore don't create or read non existent data. + 2006-10-25 John W. Eaton <jwe@octave.org> * Sparse.cc (assign): Clear lhs index after error.
--- a/liboctave/Sparse.cc +++ b/liboctave/Sparse.cc @@ -870,13 +870,13 @@ if (c > nc) { - for (octave_idx_type i = 0; i < nc; i++) + for (octave_idx_type i = 0; i < nc + 1; i++) tmpval.cidx(i) = xcidx(i); - for (octave_idx_type i = nc+2; i < c; i++) + for (octave_idx_type i = nc + 1; i < c + 1; i++) tmpval.cidx(i) = tmpval.cidx(i-1); } else if (c <= nc) - for (octave_idx_type i = 0; i < c; i++) + for (octave_idx_type i = 0; i < c + 1; i++) tmpval.cidx(i) = xcidx(i); for (octave_idx_type i = 0; i < n; i++) @@ -888,7 +888,8 @@ else { // Count how many non zero terms before we do anything - for (octave_idx_type i = 0; i < c; i++) + octave_idx_type min_nc = (c < nc ? c : nc); + for (octave_idx_type i = 0; i < min_nc; i++) for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++) if (xridx(j) < r) n++; @@ -899,7 +900,7 @@ tmpval = Sparse<T> (r, c, n); tmpval.cidx(0); - for (octave_idx_type i = 0, ii = 0; i < c; i++) + for (octave_idx_type i = 0, ii = 0; i < min_nc; i++) { for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++) if (xridx(j) < r) @@ -909,6 +910,9 @@ } tmpval.cidx(i+1) = ii; } + if (c > min_nc) + for (octave_idx_type i = nc; i < c; i++) + tmpval.cidx(i+1) = tmpval.cidx(i); } else tmpval = Sparse<T> (r, c);