Mercurial > octave
changeset 30968:9a9374ed5270 stable
findobj.m: Fix input validation of graphics handles (bug #62378)
* findobj.m: Check validity of all input graphics handles, not just the first
one. Re-order input validation to error out first and have ordinary code
second. Add BIST tests for bug #62378.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 29 Apr 2022 22:13:37 -0700 |
parents | 42cf34140699 |
children | 29573bab8328 7d5cb3dd312d |
files | scripts/plot/util/findobj.m |
diffstat | 1 files changed, 21 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/findobj.m Fri Apr 22 07:43:33 2022 -0700 +++ b/scripts/plot/util/findobj.m Fri Apr 29 22:13:37 2022 -0700 @@ -101,28 +101,30 @@ handles = 0; n1 = 0; else - if (! isempty (varargin{1})) - if (ishghandle (varargin{1}(1))) - handles = varargin{1}; - n1 = 2; - else - handles = 0; - n1 = 1; - endif - else + if (isempty (varargin{1})) ## Return [](0x1) for compatibility. h = zeros (0, 1); return; endif + arg1 = varargin{1}; + if (isnumeric (arg1)) + if (! all (ishghandle (arg1))) + error ("findobj: invalid graphics handles in input HLIST"); + endif + handles = arg1; + n1 = 2; + else + handles = 0; + n1 = 1; + endif if (n1 <= nargin) - if (ischar (varargin{n1})) - if (strcmpi (varargin{n1}, "flat")) - depth = 0; - n1 += 1; - endif - else + if (! ischar (varargin{n1})) error ("findobj: properties and options must be strings"); endif + if (strcmpi (varargin{n1}, "flat")) + depth = 0; + n1 += 1; + endif endif endif @@ -443,3 +445,7 @@ %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect + +## Test input validation +%!error <invalid graphics handles in input HLIST> findobj ([0 1 10], "flat") +%!error <properties and options must be strings> findobj ({0}, "flat")