# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1332430488 14400 # Node ID 3959f3f81e334df0d8f086403928ed6d5ba1fb89 # Parent 51fd0cf227e45f2ec04d026f344a39acd0f592ec 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. diff --git a/src/data.cc b/src/data.cc --- 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 diag (); %!error diag (1,2,3,4);