changeset 25986:07d14d092d77

hgsave.m: Validate there is only a single graphics handle input. * hgsave.m: Verify that graphics handle input H is a scalar. Add BIST test for same.
author Rik <rik@octave.org>
date Tue, 30 Oct 2018 15:18:22 -0700
parents 49ffd0e0242d
children 9618c2f96e7a
files scripts/plot/util/hgsave.m
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/hgsave.m	Tue Oct 30 22:50:40 2018 +0100
+++ b/scripts/plot/util/hgsave.m	Tue Oct 30 15:18:22 2018 -0700
@@ -63,12 +63,16 @@
     filename = h;
     h = get (0, "currentfigure");
     if (isempty (h))
-      error ("hgsave: No current figure to save");
+      error ("hgsave: no current figure to save");
     endif
   elseif (! (ishghandle (h) && ischar (filename)))
     print_usage ();
   endif
 
+  if (! isscalar (h))
+    error ("hgsave: H must be a single graphics handle");
+  endif
+
   ## Check file extension
   [~, ~, ext] = fileparts (filename);
   if (isempty (ext))
@@ -127,3 +131,11 @@
 %!error hgsave ()
 %!error hgsave (1, 2, 3, 4)
 %!error hgsave ("abc", "def")
+%!error <H must be a single graphics handle>
+%! unwind_protect
+%!   hf = figure ("visible", "off");
+%!   hax = axes ();
+%!   hgsave ([hf, hax], "foobar");
+%! unwind_protect_cleanup
+%!   close (hf);
+%! end_unwind_protect