diff scripts/image/gray.m @ 32737:d8e5e55c3cf5

Tighten input validation for all colormaps (bug #65011). * autumn.m, bone.m, colorcube.m, cool.m, copper.m, cubehelix.m, flag.m, gray.m, hot.m, hsv.m, jet.m, lines.m, movie.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, turbo.m, viridis.m, white.m, winter.m: Check input N is scalar, real, and integer. Update BIST tests.
author Rik <rik@octave.org>
date Thu, 11 Jan 2024 22:06:54 -0800
parents 8dfe116fb0fe
children
line wrap: on
line diff
--- a/scripts/image/gray.m	Thu Jan 11 17:10:08 2024 -0800
+++ b/scripts/image/gray.m	Thu Jan 11 22:06:54 2024 -0800
@@ -38,8 +38,8 @@
 function map = gray (n)
 
   if (nargin == 1)
-    if (! isscalar (n))
-      error ("gray: N must be a scalar");
+    if (! (isscalar (n) && isreal (n) && n == fix (n)))
+      error ("gray: N must be a scalar integer");
     endif
     n = double (n);
   else
@@ -86,6 +86,6 @@
 %!assert (gray (11), [0:.1:1]' .* [1, 1, 1], eps)
 
 ## Input validation
-%!error <N must be a scalar> gray ("foo")
-%!error <N must be a scalar> gray ([1, 2, 3])
-%!error <N must be a scalar> gray ({1, 2, 3})
+%!error <N must be a scalar integer> gray ("foo")
+%!error <N must be a scalar integer> gray ([1, 2, 3])
+%!error <N must be a scalar integer> gray ({1, 2, 3})