changeset 32043:9ef7e38d57b8

Fix segfault when set() is used with too few inputs (bug #64072) * graphics.cc (graphics_object::set (const octave_value_list& args)): Add FIXME note. This function should only be processing name/value pairs, but contains code for processing a single struct input as well. * graphics.cc (Fset): For calling forms with 2 inputs check that there is a second argument before attempting to retrieve it.
author Rik <rik@octave.org>
date Thu, 20 Apr 2023 11:32:11 -0700
parents ded0fd45bf68
children 31f7f5359ba2
files libinterp/corefcn/graphics.cc
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Apr 20 08:47:02 2023 +0200
+++ b/libinterp/corefcn/graphics.cc	Thu Apr 20 11:32:11 2023 -0700
@@ -2562,7 +2562,10 @@
 
   for (int i = 0; i < nargin; )
     {
-      if (args(i).isstruct () )
+      // FIXME: Should this if branch be eliminated and determination of
+      // struct input be determined earlier such that the correct set(...)
+      // function is invoked by the compiler?
+      if (args(i).isstruct ())
         {
           set (args(i).map_value ());
           i++;
@@ -12258,7 +12261,7 @@
       // Loop over input arguments
       for (octave_idx_type i = 1; i < args.length (); )
         {
-          if (i < nargin && args(i).iscellstr () && args(i+1).iscell ())
+          if ((i < nargin - 1) && args(i).iscellstr () && args(i+1).iscell ())
             {
               if (args(i+1).cell_value ().rows () == 1)
                 go.set (args(i).cellstr_value (), args(i+1).cell_value (), 0);
@@ -12276,13 +12279,13 @@
             go.set (args(i).map_value ());
             i += 1;
           }
-          else if (i < nargin)
+          else if (i < nargin - 1)
           {
             go.set (args.slice (i, 2));
             i += 2;
           }
           else
-            error ("set: invalid syntax at input #%" OCTAVE_IDX_TYPE_FORMAT, i);
+            error ("set: invalid syntax at input #%" OCTAVE_IDX_TYPE_FORMAT, i+1);
         }
 
       request_drawnow = true;