Mercurial > hg > octave-nkf
diff libinterp/corefcn/data.cc @ 17915:56d2b6838405
Issue an error if reshape called with just a single dimension.
* data.cc (Freshape): Issue an error if reshape called with just a single
dimension. Add more %!error input validation tests.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 12 Nov 2013 22:37:50 -0800 |
parents | 573f865aa8c8 |
children | 6a71e5030df5 7eeaecac9b5b ac0c04e4d141 |
line wrap: on
line diff
--- a/libinterp/corefcn/data.cc +++ b/libinterp/corefcn/data.cc @@ -4953,6 +4953,12 @@ { Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); + if (new_size.length () < 2) + { + error ("reshape: SIZE must have 2 or more dimensions"); + return retval; + } + new_dims = dim_vector::alloc (new_size.length ()); for (octave_idx_type i = 0; i < new_size.length (); i++) @@ -5044,10 +5050,15 @@ %!test %! s.a = 1; -%! fail ("reshape (s, 2, 3)"); +%! fail ("reshape (s, 2, 3)", "can't reshape 1x1 array to 2x3 array"); %!error reshape () %!error reshape (1, 2, 3, 4) +%!error <SIZE must have 2 or more dimensions> reshape (1:3, 3) +%!error <SIZE must be non-negative> reshape (1:3, [3 -1]) +%!error <only a single dimension can be unknown> reshape (1:3, 1,[],[],3) +%!error <SIZE must be non-negative> reshape (1:3, 3, -1) +%!error <SIZE is not divisible> reshape (1:3, 3, [], 2) */ DEFUN (vec, args, ,