# HG changeset patch # User John W. Eaton # Date 1552577198 0 # Node ID ae9f8906e2cb98616946e7e8421aa9652eec9156 # Parent 075c4d3bf1de2d1fb448224f61dca96b9dc9de10 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. diff -r 075c4d3bf1de -r ae9f8906e2cb scripts/plot/util/clf.m --- 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