changeset 25233:c64f7a95b464

pie.m, pie3.m: Validate that data input is finite (bug #53480). * pie.m, pie3.m: Use isfinite() to check input data X. Add BIST tests for input validation.
author Rik <rik@octave.org>
date Thu, 12 Apr 2018 13:30:50 -0700
parents 8a92b651838b
children b02d5a4c7452
files scripts/plot/draw/pie.m scripts/plot/draw/pie3.m
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/draw/pie.m	Thu Apr 12 13:19:25 2018 -0700
+++ b/scripts/plot/draw/pie.m	Thu Apr 12 13:30:50 2018 -0700
@@ -60,6 +60,10 @@
     print_usage ();
   endif
 
+  if (! all (isfinite (varargin{1})))
+    error ("pie: all data in X must be finite"); 
+  endif
+
   oldfig = [];
   if (! isempty (hax))
     oldfig = get (0, "currentfigure");
@@ -100,3 +104,8 @@
 %! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
 %! title ("pie() with missing slice");
+
+## Test input validation
+%!error pie ()
+%!error <all data in X must be finite> pie ([1 2 Inf])
+%!error <all data in X must be finite> pie ([1 2 NaN])
--- a/scripts/plot/draw/pie3.m	Thu Apr 12 13:19:25 2018 -0700
+++ b/scripts/plot/draw/pie3.m	Thu Apr 12 13:30:50 2018 -0700
@@ -61,6 +61,10 @@
     print_usage ();
   endif
 
+  if (! all (isfinite (varargin{1})))
+    error ("pie3: all data in X must be finite"); 
+  endif
+
   oldfig = [];
   if (! isempty (hax))
     oldfig = get (0, "currentfigure");
@@ -100,3 +104,8 @@
 %! colormap ([1,0,0;0,1,0;0,0,1;1,1,0;1,0,1;0,1,1]);
 %! axis ([-2,2,-2,2]);
 %! title ("pie3() with missing slice");
+
+## Test input validation
+%!error pie3 ()
+%!error <all data in X must be finite> pie3 ([1 2 Inf])
+%!error <all data in X must be finite> pie3 ([1 2 NaN])