Mercurial > hg > octave-nkf
changeset 14490:3959f3f81e33 stable
Initialise memory in non-square diag call (bug #35946)
* diag.cc (Fdiag): Initialise memory in call to resize(), and write a
test to check for this.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 22 Mar 2012 11:34:48 -0400 |
parents | 51fd0cf227e4 |
children | 5bd9e47e9277 b472596cd7b9 |
files | src/data.cc |
diffstat | 1 files changed, 4 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/data.cc +++ b/src/data.cc @@ -1294,7 +1294,7 @@ { octave_idx_type m = args(1).int_value (), n = args(2).int_value (); if (! error_state) - retval = arg0.diag ().resize (dim_vector (m, n)); + retval = arg0.diag ().resize (dim_vector (m, n), true); else error ("diag: invalid dimensions"); } @@ -1341,6 +1341,9 @@ %!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3])); %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3])); +## Test non-square size +%!assert(diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0]) + %% Test input validation %!error <Invalid call to diag> diag (); %!error <Invalid call to diag> diag (1,2,3,4);