changeset 26319:4764e9c0face stable

Stop creating orphaned graphic handles if two "parent" properties given (bug #55322). * graphics.cc (make_graphics_object): Increment loop index variable by 2 so that property/value PAIRS are processed as one unit. If "parent" property is found, decrease loop index variable by 2 so that increment will leave index in the same position in the list of property/value pairs. This accounts for the splice operation which removes two arguments from the list. * test/bug-55322/bug-55322.tst: New test file for bug #55322. * test/bug-55322/module.mk: Add test to build system.
author Rik <rik@octave.org>
date Sat, 29 Dec 2018 18:59:33 -0800
parents e1b849489e73
children 92c88ff62055
files libinterp/corefcn/graphics.cc test/bug-55322/bug-55322.tst test/bug-55322/module.mk
diffstat 3 files changed, 47 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Sat Dec 29 13:12:21 2018 +0100
+++ b/libinterp/corefcn/graphics.cc	Sat Dec 29 18:59:33 2018 -0800
@@ -12441,7 +12441,9 @@
 
   caseless_str p ("parent");
 
-  for (int i = 0; i < xargs.length (); i++)
+  // Remove all "parent" property overrides of the first argument to function
+  // and accept only the last one (bug #55322).
+  for (int i = 0; i < xargs.length (); i += 2)
     {
       if (xargs(i).is_string () && p.compare (xargs(i).string_value ()))
         {
@@ -12452,7 +12454,7 @@
           val = xargs(i+1).double_value ();
 
           xargs = xargs.splice (i, 2);
-          break;
+          i -= 2;
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55322/bug-55322.tst	Sat Dec 29 18:59:33 2018 -0800
@@ -0,0 +1,39 @@
+## Copyright (C) 2018 Rik Wehbring
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   hax = axes ("parent", hf);
+%!   hg = hggroup ();
+%!   hl = line (hax, [0, 1], [1, 1], "parent", hax, "parent", hg);
+%!   assert (get (hax, "children"), hg);
+%!   assert (get (hg, "children"), hl);
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
+
+%!test
+%! hf = figure ("visible", "off");
+%! unwind_protect
+%!   hax = axes ();
+%!   hg = hggroup ();
+%!   hl = line ([0, 1], [1, 1], "tag", "parent", "color", "r");
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-55322/module.mk	Sat Dec 29 18:59:33 2018 -0800
@@ -0,0 +1,4 @@
+bug_55322_TEST_FILES = \
+  %reldir%/bug-55322.tst
+
+TEST_FILES += $(bug_55322_TEST_FILES)