# HG changeset patch # User jwe # Date 1161888242 0 # Node ID 9e70afeb2ebf797964d36ca769cebb47ec19fa58 # Parent 8137e2bbd1dd44e916fad6e0961a68fc61cbedc5 [project @ 2006-10-26 18:44:02 by jwe] diff -r 8137e2bbd1dd -r 9e70afeb2ebf liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Oct 26 16:01:46 2006 +0000 +++ b/liboctave/ChangeLog Thu Oct 26 18:44:02 2006 +0000 @@ -1,3 +1,9 @@ +2006-10-26 David Bateman + + * Sparse.cc (Sparse::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 * Sparse.cc (assign): Clear lhs index after error. diff -r 8137e2bbd1dd -r 9e70afeb2ebf liboctave/Sparse.cc --- a/liboctave/Sparse.cc Thu Oct 26 16:01:46 2006 +0000 +++ b/liboctave/Sparse.cc Thu Oct 26 18:44:02 2006 +0000 @@ -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 (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 (r, c);