# HG changeset patch # User Pantxo Diribarne # Date 1368108887 -7200 # Node ID ec31ca0a581253c99a1c0b0f6ee9106a8127e331 # Parent e7692efcbd0d316659b84749c90cccc77af4b71f fill.m: Improve input validation to avoid endless loops (bug #38927). * scripts/plot/draw/fill.m: check input colorspec argument and apply option/value pair arguments to all patches. Simplify __find_patches__ subfunction to avoid endless loops. Add iscolorspec subfunction to check input arguments. diff -r e7692efcbd0d -r ec31ca0a5812 scripts/plot/draw/fill.m --- a/scripts/plot/draw/fill.m Tue Oct 08 23:18:17 2013 +0200 +++ b/scripts/plot/draw/fill.m Thu May 09 16:14:47 2013 +0200 @@ -72,6 +72,15 @@ hlist = []; iargs = __find_patches__ (varargin{:}); + opts = {}; + if (numel (varargin) > iargs(end) + 2) + opts = varargin(iargs(end) + (3:end)); + endif + + if (! all (cellfun (@(x) iscolorspec (x), varargin(iargs + 2)))) + print_usage (); + endif + oldfig = []; if (! isempty (hax)) oldfig = get (0, "currentfigure"); @@ -82,16 +91,13 @@ set (hax, "nextplot", "add"); for i = 1 : length (iargs) - if (i == length (iargs)) - args = varargin(iargs(i):end); - else - args = varargin(iargs(i):iargs(i+1)-1); - endif + args = [varargin(iargs(i) + (0:2)) opts]; + [htmp, fail] = __patch__ (hax, args{:}); if (fail) print_usage (); endif - hlist(end + 1, 1) = htmp; + hlist(end+1, 1) = htmp; endfor if (strcmp (old_nxtplt, "replace")) @@ -111,45 +117,25 @@ endfunction function iargs = __find_patches__ (varargin) - iargs = []; - i = 1; - while (i < nargin) - iargs(end + 1) = i; - if (ischar (varargin{i}) - && (strcmpi (varargin{i}, "faces") - || strcmpi (varargin{i}, "vertices"))) - i += 4; - elseif (isnumeric (varargin{i})) - i += 2; - endif + iargs = 1:3:nargin; + optidx = find (! cellfun (@isnumeric, varargin(iargs)), 1); + iargs(optidx:end) = []; +endfunction - if (i <= nargin) - while (true); - if (ischar (varargin{i}) - && (strcmpi (varargin{i}, "faces") - || strcmpi (varargin{i}, "vertices"))) - break; - elseif (isnumeric (varargin{i})) - ## Assume its the colorspec - i++; - break; - elseif (ischar (varargin{i})) - colspec = tolower (varargin{i}); - collen = length (colspec); - if (any (strncmp (colspec, - {"blue", "black", "k", "red", "green", ... - "yellow", "magenta", "cyan", "white"}, - collen))) - i++; - break; - endif - else - i += 2; - endif - endwhile +function retval = iscolorspec (arg) + retval = false; + if (ischar (arg)) + persistent colors = {"y", "yellow", "r", "red", "m", "magenta", ... + "c", "cyan", "g", "green", "b", "blue", ... + "w", "white", "k", "black"}; + if (any (strcmpi (arg, colors))) + retval = true; endif - endwhile - + elseif (isvector (arg)) + if (length (arg) == 3 || all (arg >= 0 && arg <=1)) + retval = true; + endif + endif endfunction