Mercurial > octave
changeset 24151:ea06ac500348
Use stricter input validation for contour functions (bug #52176).
* __contour__.m: Verify that sizes of X,Y,Z match if they are all matrices, or
verify that rows and columns of Z match Y and X vectors.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 17 Oct 2017 08:58:58 -0700 |
parents | a386810e8693 |
children | 8f04d48bb1a0 |
files | scripts/plot/draw/private/__contour__.m |
diffstat | 1 files changed, 25 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/draw/private/__contour__.m Tue Oct 17 15:45:07 2017 +0200 +++ b/scripts/plot/draw/private/__contour__.m Tue Oct 17 08:58:58 2017 -0700 @@ -73,14 +73,36 @@ z1 = varargin{3}; x1 = 1 : columns (z1); y1 = 1 : rows (z1); + if (! ismatrix (z1)) + error ("__contour__: Z must be a 2-D matrix"); + endif else x1 = varargin{3}; y1 = varargin{4}; z1 = varargin{5}; + if (! ismatrix (z1) || ! ismatrix (x1) || ! ismatrix (y1)) + error ("__contour__: X, Y, and Z must be matrices"); + endif + if (isvector (x1)) + if (columns (z1) != length (x1)) + error ("__contour__: size of X must match number of columns in Z"); + endif + else + if (! size_equal (x1, z1)) + error ("__contour__: size of X and Z must match"); + endif + endif + if (isvector (y1)) + if (rows (z1) != length (y1)) + error ("__contour__: size of Y must match number of rows in Z"); + endif + else + if (! size_equal (y1, z1)) + error ("__contour__: size of Y and Z must match"); + endif + endif endif - if (! ismatrix (z1) || ! ismatrix (x1) || ! ismatrix (y1)) - error ("__contour__: X, Y, and Z must be matrices"); - endif + if (length (varargin) == 4 || length (varargin) == 6) vn = varargin{end}; vnauto = false;