# HG changeset patch # User Rik # Date 1682015531 25200 # Node ID 9ef7e38d57b8840c6f8f8792015d9fed03ec9a1e # Parent ded0fd45bf68eb0305f40cfccdb7e25739571acc 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. diff -r ded0fd45bf68 -r 9ef7e38d57b8 libinterp/corefcn/graphics.cc --- 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;