Mercurial > hg > octave-nkf
changeset 6216:74ca56e4414c
[project @ 2006-12-22 17:45:47 by jwe]
author | jwe |
---|---|
date | Fri, 22 Dec 2006 17:45:47 +0000 |
parents | 516d3071b34c |
children | 95084cd8723c |
files | liboctave/ChangeLog liboctave/dim-vector.h |
diffstat | 2 files changed, 28 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2006-12-22 John W. Eaton <jwe@octave.org> + + * dim-vector.h (dim_vector::dim_vector): Always start with at + least 2 dimensions. + (dim_vector::resize): Don't allow resizing to fewer than 2 dimensions. + 2006-12-06 Michael Goffioul <michael.goffioul@swing.be> * lo-sysdep.cc (opendir): Avoid passing \\* to FindFirstFile.
--- a/liboctave/dim-vector.h +++ b/liboctave/dim-vector.h @@ -28,6 +28,7 @@ #include <sstream> #include <string> +#include "lo-error.h" #include "oct-types.h" class @@ -43,14 +44,23 @@ int ndims; int count; - dim_vector_rep (void) : dims (0), ndims (0), count (1) { } + dim_vector_rep (void) + : dims (new octave_idx_type [2]), ndims (2), count (1) + { + dims[0] = 0; + dims[1] = 0; + } - dim_vector_rep (octave_idx_type n) : dims (new octave_idx_type [1]), ndims (1), count (1) + + dim_vector_rep (octave_idx_type n) + : dims (new octave_idx_type [2]), ndims (2), count (1) { dims[0] = n; + dims[1] = 1; } - dim_vector_rep (octave_idx_type r, octave_idx_type c) : dims (new octave_idx_type [2]), ndims (2), count (1) + dim_vector_rep (octave_idx_type r, octave_idx_type c) + : dims (new octave_idx_type [2]), ndims (2), count (1) { dims[0] = r; dims[1] = c; @@ -75,7 +85,8 @@ } } - dim_vector_rep (octave_idx_type n, const dim_vector_rep *dv, int fill_value = 0) + dim_vector_rep (octave_idx_type n, const dim_vector_rep *dv, + int fill_value = 0) : dims ((dv && n > 0) ? new octave_idx_type [n] : 0), ndims (n > 0 ? n : 0), count (1) { @@ -200,6 +211,13 @@ if (n != len) { + if (n < 2) + { + (*current_liboctave_error_handler) + ("unable to resize object to fewer than 2 dimensions"); + return; + } + dim_vector_rep *old_rep = rep; rep = new dim_vector_rep (n, old_rep, fill_value);