Mercurial > octave
changeset 26911:ae9f8906e2cb
avoid possible cellfun and indexing errors in clf (bug #55921)
* clf.m: Handle possibility that allchild may return an empty array
when a figure has no children or that "get" may return a single value
instead of a cell array when a figure has only one child.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 14 Mar 2019 15:26:38 +0000 |
parents | 075c4d3bf1de |
children | b54d9581b1ac |
files | scripts/plot/util/clf.m |
diffstat | 1 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/util/clf.m Thu Mar 14 08:00:59 2019 +0000 +++ b/scripts/plot/util/clf.m Thu Mar 14 15:26:38 2019 +0000 @@ -72,16 +72,27 @@ if (do_reset) ## Delete all the children, including the ones with hidden handles, ## except default menus and toolbar. + kids = allchild (hfig); - ismenu = cellfun (@(s) strncmp (s, "__default_menu_", 15), ... - get (kids, "tag")); - istoolbar = cellfun (@(s) strncmp (s, "__default_toolbar_menu_", 18), ... - get (kids, "tag")); - delete (kids(! ismenu & ! istoolbar)); + + if (! isempty (kids)) + tags = get (kids, "tag"); + ## It's possible for a figure to have just one child and then get + ## will return a single value instead of a cell array. + if (! iscell (tags)) + tags = {tags}; + endif + ismenu = cellfun (@(s) strncmp (s, "__default_menu_", 15), tags); + istoolbar = cellfun (@(s) strncmp (s, "__default_toolbar_menu_", 18), tags); + delete (kids(! ismenu & ! istoolbar)); + endif + reset (hfig); - ## Recover figure listeners which have been deleted - __add_default_menu__ (hfig, kids(ismenu), kids(istoolbar)); + if (! isempty (kids)) + ## Recover figure listeners which have been deleted + __add_default_menu__ (hfig, kids(ismenu), kids(istoolbar)); + endif __set_default_mouse_modes__ (hfig); else