changeset 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 d022061c288d
children d1978e7364ad
files scripts/ChangeLog scripts/plot/contourc.m scripts/plot/private/__contour__.m scripts/plot/surface.m scripts/plot/surfnorm.m
diffstat 5 files changed, 26 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri May 14 06:59:41 2010 +0200
+++ b/scripts/ChangeLog	Sun May 16 18:28:59 2010 -0700
@@ -1,3 +1,9 @@
+2010-05-16  Rik <octave@nomad.inbox5.com>
+
+        * scripts/plot/contourc.m, scripts/plot/private/__contour__.m, 
+          scripts/plot/surface.m, scripts/plot/surfnorm.m: Check input
+          arguments for size and type (bug #29861).
+
 2010-05-13  John W. Eaton  <jwe@octave.org>
 
 	* help/help.m: Avoid unnecessary use of varargout.
--- a/scripts/plot/contourc.m	Fri May 14 06:59:41 2010 +0200
+++ b/scripts/plot/contourc.m	Sun May 16 18:28:59 2010 -0700
@@ -64,9 +64,6 @@
   if (nargin == 1)
     vn = 10;
     z = varargin{1};
-    [nr, nc] = size (z);
-    x = 1:nc;
-    y = 1:nr;
   elseif (nargin == 2)
     vn = varargin{2};
     z = varargin{1};
@@ -87,6 +84,10 @@
     print_usage ();
   endif
 
+  if (!ismatrix (z) || isvector (z) || isscalar (z))
+    error ("contourc: z argument must be a matrix");
+  endif
+
   if (isscalar (vn))
     vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1);
   else
--- a/scripts/plot/private/__contour__.m	Fri May 14 06:59:41 2010 +0200
+++ b/scripts/plot/private/__contour__.m	Sun May 16 18:28:59 2010 -0700
@@ -88,6 +88,9 @@
     y1 = varargin{4};
     z1 = varargin{5};
   endif
+  if (!ismatrix (z1) || isvector (z1) || isscalar (z1))
+    error ("__contour__: z argument must be a matrix");
+  endif
   if (length (varargin) == 4 || length (varargin) == 6)
     vn = varargin {end};
     vnauto = false;
--- 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;
--- a/scripts/plot/surfnorm.m	Fri May 14 06:59:41 2010 +0200
+++ b/scripts/plot/surfnorm.m	Sun May 16 18:28:59 2010 -0700
@@ -71,8 +71,12 @@
     ioff = 4;
   endif
 
-  if (nargout == 0)
+  if (!ismatrix (z) || isvector (z) || isscalar (z))
+    error ("surfnorm: z argument must be a matrix");
   endif
+  if (! size_equal (x, y, z))
+    error ("surfnorm: x, y, and z must have the same dimensions");
+  endif 
 
   ## Make life easier, and avoid having to do the extrapolation later, do
   ## a simpler linear extrapolation here. This is approximative, and works