# HG changeset patch # User Arun Giridhar # Date 1641239345 28800 # Node ID 913f765057d9c4d42d9b53782c6ba640843c329e # Parent ed17822e766250434fae78c37185cfbc49b6e45b poly.m: Improve input validation (bug #61759) * poly.m: Add checks for non-numeric input, N-dimensional arrays, and non-square matrices. Add BIST tests. diff -r ed17822e7662 -r 913f765057d9 scripts/polynomial/poly.m --- a/scripts/polynomial/poly.m Sat Jan 01 19:43:52 2022 -0800 +++ b/scripts/polynomial/poly.m Mon Jan 03 11:49:05 2022 -0800 @@ -61,17 +61,21 @@ print_usage (); endif - m = min (size (x)); - n = max (size (x)); - if (m == 0) + if (! isnumeric (x)) + error ("poly: input must be numeric, not type %s", class (x)); + elseif (ndims (x) > 2) + error ("poly: input must be a vector or a square matrix"); + elseif (isempty (x)) y = 1; return; - elseif (m == 1) + elseif (isvector (x)) + n = numel (x); v = x; - elseif (m == n) + elseif (! issquare (x)) + error ("poly: input matrix must be square"); + else + n = size (x,1); v = eig (x); - else - print_usage (); endif y = zeros (1, n+1); @@ -113,4 +117,7 @@ %! assert (y, [1 + 0i, -9 - 3i, 25 + 24i, -17 - 57i, -12 + 36i]); %!error poly () -%!error poly ([1, 2, 3; 4, 5, 6]) +%!error poly ("foo") +%!error poly ({1, "foo"; "bar", 1}) +%!error poly (ones (2, 2, 2)) +%!error poly ([1, 2, 3; 4, 5, 6])