diff scripts/plot/surface.m @ 10634:60542efcfa2c

Check input arguments for size and type (bug #29861). Prevents segmentation fault with odd inputs.
author Rik <octave@nomad.inbox5.com>
date Sun, 16 May 2010 18:28:59 -0700
parents 95c3e38098bf
children 1740012184f9
line wrap: on
line diff
--- a/scripts/plot/surface.m	Fri May 14 06:59:41 2010 +0200
+++ b/scripts/plot/surface.m	Sun May 16 18:28:59 2010 -0700
@@ -18,7 +18,7 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c})
+## @deftypefn  {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c})
 ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z})
 ## @deftypefnx {Function File} {} surface (@var{z}, @var{c})
 ## @deftypefnx {Function File} {} surface (@var{z})
@@ -82,7 +82,7 @@
     c = varargin{4};
 
     if (! size_equal (z, c))
-      error ("surface: z and c must have same size");
+      error ("surface: z and c must have the same size");
     endif
     if (isvector (x) && isvector (y) && ismatrix (z))
       if (rows (z) == length (y) && columns (z) == length (x))
@@ -93,7 +93,7 @@
       endif
     elseif (ismatrix (x) && ismatrix (y) && ismatrix (z))
       if (! size_equal (x, y, z))
-        error ("surface: x, y, and z must have same dimensions");
+        error ("surface: x, y, and z must have the same dimensions");
       endif
     else
       error ("surface: x and y must be vectors and z must be a matrix");
@@ -112,7 +112,7 @@
       endif
     elseif (ismatrix (x) && ismatrix (y) && ismatrix (z))
       if (! size_equal (x, y, z))
-        error ("surface: x, y, and z must have same dimensions");
+        error ("surface: x, y, and z must have the same dimensions");
       endif
     else
       error ("surface: x and y must be vectors and z must be a matrix");
@@ -120,22 +120,22 @@
   elseif (firststring == 3)    
     z = varargin{1};
     c = varargin{2};
-    if (ismatrix (z))
+    if (ismatrix (z) && !isvector (z) && !isscalar (z))
       [nr, nc] = size (z);
       x = 1:nc;
       y = (1:nr)';
     else
-      error ("surface: argument must be a matrix");
+      error ("surface: z argument must be a matrix");
     endif
   elseif (firststring == 2)    
     z = varargin{1};
     c = z;
-    if (ismatrix (z))
+    if (ismatrix (z) && !isvector (z) && !isscalar (z))
       [nr, nc] = size (z);
       x = 1:nc;
       y = (1:nr)';
     else
-      error ("surface: argument must be a matrix");
+      error ("surface: z argument must be a matrix");
     endif
   else
     bad_usage = true;